mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-27 09:12:44 +00:00
Bring in the 4.4 Lite games directory, modulo man page changes and segregation
of the x11 based games. I'm not going to tag the originals with bsd_44_lite and do this in two stages since it's just not worth it for this collection, and I've got directory renames to deal with that way. Bleah. Submitted by: jkh
This commit is contained in:
parent
28178404af
commit
554eb505f8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/unlabeled-1.1.1/; revision=2490
13
games/Makefile
Normal file
13
games/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
# @(#)Makefile 8.2 (Berkeley) 3/31/94
|
||||
|
||||
SUBDIR= adventure arithmetic atc backgammon battlestar bcd boggle caesar \
|
||||
canfield chess ching cribbage dm factor fish fortune hack hangman \
|
||||
larn mille monop morse number phantasia pig pom ppt primes quiz \
|
||||
rain random robots rogue sail snake tetris trek wargames worm worms \
|
||||
wump
|
||||
|
||||
.if exists(${X11BASE}/lib/libX11.a}
|
||||
SUBDIR+= xneko xroach
|
||||
.endif
|
||||
|
||||
.include <bsd.subdir.mk>
|
9
games/Makefile.inc
Normal file
9
games/Makefile.inc
Normal file
@ -0,0 +1,9 @@
|
||||
# @(#)Makefile.inc 8.1 (Berkeley) 5/31/93
|
||||
|
||||
BINOWN?= games
|
||||
.if defined(HIDEGAME)
|
||||
BINDIR?= /usr/games/hide
|
||||
BINMODE?= 4700
|
||||
.else
|
||||
BINDIR?= /usr/games
|
||||
.endif
|
16
games/adventure/Makefile
Normal file
16
games/adventure/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/12/93
|
||||
|
||||
PROG= adventure
|
||||
SRCS= main.c init.c done.c save.c subr.c vocab.c wizard.c io.c data.c crc.c
|
||||
MAN6= adventure.6
|
||||
CFLAGS+=-traditional-cpp
|
||||
HIDEGAME=hidegame
|
||||
CLEANFILES+=setup data.c
|
||||
|
||||
data.c: glorkz setup
|
||||
./setup ${.CURDIR}/glorkz > data.c
|
||||
|
||||
setup: setup.c hdr.h
|
||||
${CC} -o setup ${.CURDIR}/setup.c
|
||||
|
||||
.include <bsd.prog.mk>
|
57
games/adventure/adventure.6
Normal file
57
games/adventure/adventure.6
Normal file
@ -0,0 +1,57 @@
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)adventure.6 8.1 (Berkeley) 5/31/93
|
||||
.\"
|
||||
.Dd May 31, 1993
|
||||
.Dt ADVENTURE 6
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm adventure
|
||||
.Nd an exploration game
|
||||
.Sh SYNOPSIS
|
||||
.Nm adventure
|
||||
.Op saved-file
|
||||
.Sh DESCRIPTION
|
||||
The object of the game is to locate and explore Colossal Cave, find the
|
||||
treasures hidden there, and bring them back to the building with you.
|
||||
The program is self-descriptive to a point, but part of the game is to
|
||||
discover its rules.
|
||||
.Pp
|
||||
To terminate a game, enter
|
||||
.Dq quit ;
|
||||
to save a game for later resumption, enter
|
||||
.Dq suspend .
|
134
games/adventure/crc.c
Normal file
134
games/adventure/crc.c
Normal file
@ -0,0 +1,134 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 */
|
||||
|
||||
typedef unsigned long u_long;
|
||||
|
||||
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;
|
||||
int step;
|
||||
|
||||
crc_start()
|
||||
{
|
||||
crcval = step = 0;
|
||||
}
|
||||
|
||||
u_long crc(ptr, nr) /* Process nr bytes at a time; ptr points to them */
|
||||
char *ptr;
|
||||
int nr;
|
||||
{
|
||||
register int i;
|
||||
register 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. */
|
||||
}
|
138
games/adventure/done.c
Normal file
138
games/adventure/done.c
Normal file
@ -0,0 +1,138 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 "hdr.h"
|
||||
|
||||
score() /* sort of like 20000 */
|
||||
{ register 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;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
die(entry) /* label 90 */
|
||||
int entry;
|
||||
{ register 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;
|
||||
return(2000);
|
||||
}
|
1815
games/adventure/glorkz
Normal file
1815
games/adventure/glorkz
Normal file
File diff suppressed because it is too large
Load Diff
164
games/adventure/hdr.h
Normal file
164
games/adventure/hdr.h
Normal file
@ -0,0 +1,164 @@
|
||||
/*-
|
||||
* 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.
|
||||
*
|
||||
* @(#)hdr.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
/* ADVENTURE -- Jim Gillogly, Jul 1977
|
||||
* This program is a re-write of ADVENT, written in FORTRAN mostly by
|
||||
* Don Woods of SAIL. In most places it is as nearly identical to the
|
||||
* original as possible given the language and word-size differences.
|
||||
* A few places, such as the message arrays and travel arrays were changed
|
||||
* to reflect the smaller core size and word size. The labels of the
|
||||
* original are reflected in this version, so that the comments of the
|
||||
* fortran are still applicable here.
|
||||
*
|
||||
* The data file distributed with the fortran source is assumed to be called
|
||||
* "glorkz" in the directory where the program is first run.
|
||||
*/
|
||||
|
||||
/* hdr.h: included by c advent files */
|
||||
|
||||
int datfd; /* message file descriptor */
|
||||
int delhit;
|
||||
int yea;
|
||||
extern char data_file[]; /* Virtual data file */
|
||||
|
||||
#define TAB 011
|
||||
#define LF 012
|
||||
#define FLUSHLINE while (getchar()!='\n')
|
||||
#define FLUSHLF while (next()!=LF)
|
||||
|
||||
int loc,newloc,oldloc,oldlc2,wzdark,gaveup,kq,k,k2;
|
||||
char *wd1,*wd2; /* the complete words */
|
||||
int verb,obj,spk;
|
||||
extern int blklin;
|
||||
int saved,savet,mxscor,latncy;
|
||||
|
||||
#define SHORT 50 /* How short is a demo game? */
|
||||
|
||||
#define MAXSTR 20 /* max length of user's words */
|
||||
|
||||
#define HTSIZE 512 /* max number of vocab words */
|
||||
struct hashtab /* hash table for vocabulary */
|
||||
{ int val; /* word type &index (ktab) */
|
||||
char *atab; /* pointer to actual string */
|
||||
} voc[HTSIZE];
|
||||
|
||||
#define SEED 1815622 /* "Encryption" seed */
|
||||
|
||||
struct text
|
||||
#ifdef OLDSTUFF
|
||||
{ int seekadr; /* DATFILE must be < 2**16 */
|
||||
#endif OLDSTUFF
|
||||
{ char *seekadr; /* Msg start in virtual disk */
|
||||
int txtlen; /* length of msg starting here */
|
||||
};
|
||||
|
||||
#define RTXSIZ 205
|
||||
struct text rtext[RTXSIZ]; /* random text messages */
|
||||
|
||||
#define MAGSIZ 35
|
||||
struct text mtext[MAGSIZ]; /* magic messages */
|
||||
|
||||
int clsses;
|
||||
#define CLSMAX 12
|
||||
struct text ctext[CLSMAX]; /* classes of adventurer */
|
||||
int cval[CLSMAX];
|
||||
|
||||
struct text ptext[101]; /* object descriptions */
|
||||
|
||||
#define LOCSIZ 141 /* number of locations */
|
||||
struct text ltext[LOCSIZ]; /* long loc description */
|
||||
struct text stext[LOCSIZ]; /* short loc descriptions */
|
||||
|
||||
struct travlist /* direcs & conditions of travel*/
|
||||
{ struct travlist *next; /* ptr to next list entry */
|
||||
int conditions; /* m in writeup (newloc / 1000) */
|
||||
int tloc; /* n in writeup (newloc % 1000) */
|
||||
int tverb; /* the verb that takes you there*/
|
||||
} *travel[LOCSIZ],*tkk; /* travel is closer to keys(...)*/
|
||||
|
||||
int atloc[LOCSIZ];
|
||||
|
||||
int plac[101]; /* initial object placement */
|
||||
int fixd[101],fixed[101]; /* location fixed? */
|
||||
|
||||
int actspk[35]; /* rtext msg for verb <n> */
|
||||
|
||||
int cond[LOCSIZ]; /* various condition bits */
|
||||
|
||||
extern int setbit[16]; /* bit defn masks 1,2,4,... */
|
||||
|
||||
int hntmax;
|
||||
int hints[20][5]; /* info on hints */
|
||||
int hinted[20],hintlc[20];
|
||||
|
||||
int place[101], prop[101],link[201];
|
||||
int abb[LOCSIZ];
|
||||
|
||||
int maxtrs,tally,tally2; /* treasure values */
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
int keys,lamp,grate,cage,rod,rod2,steps,/* mnemonics */
|
||||
bird,door,pillow,snake,fissur,tablet,clam,oyster,magzin,
|
||||
dwarf,knife,food,bottle,water,oil,plant,plant2,axe,mirror,dragon,
|
||||
chasm,troll,troll2,bear,messag,vend,batter,
|
||||
nugget,coins,chest,eggs,tridnt,vase,emrald,pyram,pearl,rug,chain,
|
||||
spices,
|
||||
back,look,cave,null,entrnc,dprssn,
|
||||
enter, stream, pour,
|
||||
say,lock,throw,find,invent;
|
||||
|
||||
int chloc,chloc2,dseen[7],dloc[7], /* dwarf stuff */
|
||||
odloc[7],dflag,daltlc;
|
||||
|
||||
int tk[21],stick,dtotal,attack;
|
||||
int turns,lmwarn,iwest,knfloc,detail, /* various flags & counters */
|
||||
abbnum,maxdie,numdie,holdng,dkill,foobar,bonus,clock1,clock2,
|
||||
saved,closng,panic,closed,scorng;
|
||||
|
||||
int demo,newloc,limit;
|
||||
|
||||
char *malloc();
|
||||
char *decr();
|
||||
unsigned long crc();
|
||||
|
||||
/* We need to get a little tricky to avoid strings */
|
||||
#define DECR(a,b,c,d,e) decr('a'+'+','b'+'-','c'+'#','d'+'&','e'+'%')
|
216
games/adventure/init.c
Normal file
216
games/adventure/init.c
Normal file
@ -0,0 +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.
|
||||
*/
|
||||
|
||||
#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 <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#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(command) /* everything for 1st time run */
|
||||
char *command; /* command we were called with */
|
||||
{
|
||||
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;
|
||||
|
||||
/* 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++; /* main checks, treats as QUIT */
|
||||
signal(2,trapdel); /* catch subsequent DELs */
|
||||
}
|
||||
|
||||
|
||||
startup()
|
||||
{
|
||||
time_t time();
|
||||
|
||||
demo=Start(0);
|
||||
srand((int)(time((time_t *)NULL))); /* random seed */
|
||||
/* srand(371); /* non-random seed */
|
||||
hinted[3]=yes(65,1,0);
|
||||
newloc=1;
|
||||
delhit = 0;
|
||||
limit=330;
|
||||
if (hinted[3]) limit=1000; /* better batteries if instrucs */
|
||||
}
|
514
games/adventure/io.c
Normal file
514
games/adventure/io.c
Normal file
@ -0,0 +1,514 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 <stdio.h>
|
||||
|
||||
|
||||
getin(wrd1,wrd2) /* get command from user */
|
||||
char **wrd1,**wrd2; /* no prompt, usually */
|
||||
{ register 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;
|
||||
}
|
||||
default:
|
||||
if (++numch>=MAXSTR) /* string too long */
|
||||
{ printf("Give me a break!!\n");
|
||||
wd1buf[0]=wd2buf[0]=0;
|
||||
FLUSHLINE;
|
||||
return;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
confirm(mesg) /* confirm irreversible action */
|
||||
char *mesg;
|
||||
{ register int result;
|
||||
printf("%s",mesg); /* tell him what he did */
|
||||
if (getchar()=='y') /* was his first letter a 'y'? */
|
||||
result=1;
|
||||
else result=0;
|
||||
FLUSHLINE;
|
||||
return(result);
|
||||
}
|
||||
|
||||
yes(x,y,z) /* confirm with rspeak */
|
||||
int x,y,z;
|
||||
{ register int result;
|
||||
register char ch;
|
||||
for (;;)
|
||||
{ rspeak(x); /* tell him what we want*/
|
||||
if ((ch=getchar())=='y')
|
||||
result=TRUE;
|
||||
else if (ch=='n') result=FALSE;
|
||||
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;
|
||||
register char ch;
|
||||
for (;;)
|
||||
{ mspeak(x); /* tell him what we want*/
|
||||
if ((ch=getchar())=='y')
|
||||
result=TRUE;
|
||||
else if (ch=='n') result=FALSE;
|
||||
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? */
|
||||
|
||||
char iotape[] = "Ax3F'\003tt$8h\315qer*h\017nGKrX\207:!l";
|
||||
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;
|
||||
|
||||
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;
|
||||
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 *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)
|
||||
{ printf("Too many random msgs\n");
|
||||
exit(0);
|
||||
}
|
||||
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)
|
||||
{ printf("Too many magic msgs\n");
|
||||
exit(0);
|
||||
}
|
||||
mtext[oldloc].seekadr=seekhere;
|
||||
mtext[oldloc].txtlen=maystart-seekstart;
|
||||
break;
|
||||
default:
|
||||
printf("rdesc called with bad section\n");
|
||||
exit(0);
|
||||
}
|
||||
seekhere += maystart-seekstart;
|
||||
}
|
||||
if (locc<0)
|
||||
{ outsw=0; /* turn off output */
|
||||
seekhere += 3; /* -1<delimiter> */
|
||||
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;
|
||||
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); */
|
||||
entries=0;
|
||||
oldloc=locc;
|
||||
}
|
||||
for (s=buf;; *s++) /* get the newloc number /ASCII */
|
||||
if ((*s=next())==TAB || *s==LF) break;
|
||||
*s=0;
|
||||
len=length(buf)-1; /* 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));
|
||||
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;
|
||||
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 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;
|
||||
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;
|
||||
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) */
|
||||
struct text *msg;/* msg is a pointer to seek address and length of mess */
|
||||
{
|
||||
register 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 *numst, save;
|
||||
struct text *msg;
|
||||
char *tbuf;
|
||||
|
||||
msg = &ptext[m];
|
||||
if ((tbuf=(char *) malloc(msg->txtlen + 1)) == 0) bug(108);
|
||||
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);
|
||||
}
|
580
games/adventure/main.c
Normal file
580
games/adventure/main.c
Normal file
@ -0,0 +1,580 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 <sys/file.h>
|
||||
#include <stdio.h>
|
||||
#include "hdr.h"
|
||||
|
||||
|
||||
main(argc,argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
extern int errno;
|
||||
register int i;
|
||||
int rval,ll;
|
||||
struct text *kk;
|
||||
extern trapdel();
|
||||
|
||||
init(); /* Initialize everything */
|
||||
signal(2,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(0);
|
||||
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(0); /* So give up */
|
||||
case 2: /* Oops -- file was altered */
|
||||
rspeak(202); /* You dissolve */
|
||||
exit(0); /* 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(0))
|
||||
{ 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(0))
|
||||
{ abb[loc]++;
|
||||
for (i=atloc[loc]; i!=0; i=link[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(0); /* 2605 */
|
||||
if (knfloc>0 && knfloc!=loc) knfloc=1;
|
||||
getin(&wd1,&wd2);
|
||||
if (delhit) /* user typed a DEL */
|
||||
{ delhit=0; /* reset counter */
|
||||
copystr("quit",wd1); /* 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 (weq(wd1,"enter") &&
|
||||
(weq(wd2,"strea")||weq(wd2,"water")))
|
||||
goto l2010;
|
||||
if (weq(wd1,"enter") && *wd2!=0) goto l2800;
|
||||
if ((!weq(wd1,"water")&&!weq(wd1,"oil"))
|
||||
|| (!weq(wd2,"plant")&&!weq(wd2,"door")))
|
||||
goto l2610;
|
||||
if (at(vocab(wd2,1))) copystr("pour",wd2);
|
||||
|
||||
l2610: if (weq(wd1,"west"))
|
||||
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:
|
||||
printf("Error 22\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
l8:
|
||||
switch(march())
|
||||
{ case 2: continue; /* i.e. goto l2 */
|
||||
case 99:
|
||||
switch(die(99))
|
||||
{ case 2000: goto l2000;
|
||||
default: bug(111);
|
||||
}
|
||||
default: bug(110);
|
||||
}
|
||||
|
||||
l2800: copystr(wd2,wd1);
|
||||
*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||link[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(0)) 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(argv[0]); /* 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(0)) 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(0);
|
||||
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(0)!=water
|
||||
||!here(bottle))) goto l8000;
|
||||
if (obj!=0&&obj!=water) spk=110;
|
||||
if (spk==110||liq(0)!=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(0)==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(0)) 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(0)==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;
|
||||
}
|
||||
}
|
184
games/adventure/save.c
Normal file
184
games/adventure/save.c
Normal file
@ -0,0 +1,184 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "hdr.h"
|
||||
|
||||
struct savestruct
|
||||
{
|
||||
void *address;
|
||||
int width;
|
||||
};
|
||||
|
||||
struct savestruct save_array[] =
|
||||
{
|
||||
&abbnum, sizeof(abbnum),
|
||||
&attack, sizeof(attack),
|
||||
&blklin, sizeof(blklin),
|
||||
&bonus, sizeof(bonus),
|
||||
&chloc, sizeof(chloc),
|
||||
&chloc2, sizeof(chloc2),
|
||||
&clock1, sizeof(clock1),
|
||||
&clock2, sizeof(clock2),
|
||||
&closed, sizeof(closed),
|
||||
&closng, sizeof(closng),
|
||||
&daltlc, sizeof(daltlc),
|
||||
&demo, sizeof(demo),
|
||||
&detail, sizeof(detail),
|
||||
&dflag, sizeof(dflag),
|
||||
&dkill, sizeof(dkill),
|
||||
&dtotal, sizeof(dtotal),
|
||||
&foobar, sizeof(foobar),
|
||||
&gaveup, sizeof(gaveup),
|
||||
&holdng, sizeof(holdng),
|
||||
&iwest, sizeof(iwest),
|
||||
&k, sizeof(k),
|
||||
&k2, sizeof(k2),
|
||||
&knfloc, sizeof(knfloc),
|
||||
&kq, sizeof(kq),
|
||||
&latncy, sizeof(latncy),
|
||||
&limit, sizeof(limit),
|
||||
&lmwarn, sizeof(lmwarn),
|
||||
&loc, sizeof(loc),
|
||||
&maxdie, sizeof(maxdie),
|
||||
&mxscor, sizeof(mxscor),
|
||||
&newloc, sizeof(newloc),
|
||||
&numdie, sizeof(numdie),
|
||||
&obj, sizeof(obj),
|
||||
&oldlc2, sizeof(oldlc2),
|
||||
&oldloc, sizeof(oldloc),
|
||||
&panic, sizeof(panic),
|
||||
&saved, sizeof(saved),
|
||||
&savet, sizeof(savet),
|
||||
&scorng, sizeof(scorng),
|
||||
&spk, sizeof(spk),
|
||||
&stick, sizeof(stick),
|
||||
&tally, sizeof(tally),
|
||||
&tally2, sizeof(tally2),
|
||||
&tkk, sizeof(tkk),
|
||||
&turns, sizeof(turns),
|
||||
&verb, sizeof(verb),
|
||||
&wd1, sizeof(wd1),
|
||||
&wd2, sizeof(wd2),
|
||||
&wzdark, sizeof(wzdark),
|
||||
&yea, sizeof(yea),
|
||||
atloc, sizeof(atloc),
|
||||
dloc, sizeof(dloc),
|
||||
dseen, sizeof(dseen),
|
||||
fixed, sizeof(fixed),
|
||||
hinted, sizeof(hinted),
|
||||
link, sizeof(link),
|
||||
odloc, sizeof(odloc),
|
||||
place, sizeof(place),
|
||||
prop, sizeof(prop),
|
||||
tk, sizeof(tk),
|
||||
|
||||
NULL, 0
|
||||
};
|
||||
|
||||
save(outfile) /* Two passes on data: first to get checksum, second */
|
||||
char *outfile; /* to output the data using checksum to start random #s */
|
||||
{
|
||||
FILE *out;
|
||||
struct savestruct *p;
|
||||
char *s;
|
||||
long sum;
|
||||
int i;
|
||||
|
||||
crc_start();
|
||||
for (p = save_array; p->address != NULL; p++)
|
||||
sum = crc(p->address, p->width);
|
||||
srandom((int) sum);
|
||||
|
||||
if ((out = fopen(outfile, "wb")) == NULL)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Hmm. The name \"%s\" appears to be magically blocked.\n",
|
||||
outfile);
|
||||
return 1;
|
||||
}
|
||||
fwrite(&sum, sizeof(sum), 1, out); /* Here's the random() key */
|
||||
for (p = save_array; p->address != NULL; p++)
|
||||
{
|
||||
for (s = p->address, i = 0; i < p->width; i++, s++)
|
||||
*s = (*s ^ random()) & 0xFF; /* Lightly encrypt */
|
||||
fwrite(p->address, p->width, 1, out);
|
||||
}
|
||||
fclose(out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
restore(infile)
|
||||
char *infile;
|
||||
{
|
||||
FILE *in;
|
||||
struct savestruct *p;
|
||||
char *s;
|
||||
long sum, cksum;
|
||||
int i;
|
||||
|
||||
if ((in = fopen(infile, "rb")) == NULL)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Hmm. The file \"%s\" appears to be magically blocked.\n",
|
||||
infile);
|
||||
return 1;
|
||||
}
|
||||
fread(&sum, sizeof(sum), 1, in); /* Get the seed */
|
||||
srandom((int) sum);
|
||||
for (p = save_array; p->address != NULL; p++)
|
||||
{
|
||||
fread(p->address, p->width, 1, in);
|
||||
for (s = p->address, i = 0; i < p->width; i++, s++)
|
||||
*s = (*s ^ random()) & 0xFF; /* Lightly decrypt */
|
||||
}
|
||||
fclose(in);
|
||||
|
||||
crc_start(); /* See if she cheated */
|
||||
for (p = save_array; p->address != NULL; p++)
|
||||
cksum = crc(p->address, p->width);
|
||||
if (sum != cksum) /* Tsk tsk */
|
||||
return 2; /* Altered the file */
|
||||
/* We successfully restored, so this really was a save file */
|
||||
/* Get rid of the file, but don't bother checking that we did */
|
||||
return 0;
|
||||
}
|
125
games/adventure/setup.c
Normal file
125
games/adventure/setup.c
Normal file
@ -0,0 +1,125 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* Setup: keep the structure of the original Adventure port, but use an
|
||||
* internal copy of the data file, serving as a sort of virtual disk. It's
|
||||
* lightly encrypted to prevent casual snooping of the executable.
|
||||
*
|
||||
* Also do appropriate things to tabs so that bogus editors will do the right
|
||||
* thing with the data file.
|
||||
*
|
||||
*/
|
||||
|
||||
#define SIG1 " * Jim Gillogly"
|
||||
#define SIG2 " * Sterday, 6 Thrimidge S.R. 1993, 15:24"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "hdr.h" /* SEED lives in there; keep them coordinated. */
|
||||
|
||||
#define USAGE "Usage: setup file > data.c (file is typically glorkz)\n"
|
||||
|
||||
#define YES 1
|
||||
#define NO 0
|
||||
|
||||
void fatal();
|
||||
|
||||
#define LINE 10 /* How many values do we get on a line? */
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
FILE *infile;
|
||||
int c, count, linestart;
|
||||
|
||||
if (argc != 2) fatal(USAGE);
|
||||
|
||||
if ((infile = fopen(argv[1], "r")) == NULL)
|
||||
fatal("Can't read file %s.\n", argv[1]);
|
||||
puts("/*\n * data.c: created by setup from the ascii data file.");
|
||||
puts(SIG1);
|
||||
puts(SIG2);
|
||||
puts(" */");
|
||||
printf("\n\nchar data_file[] =\n{");
|
||||
srandom(SEED);
|
||||
count = 0;
|
||||
linestart = YES;
|
||||
|
||||
while ((c = getc(infile)) != EOF)
|
||||
{
|
||||
if (linestart && c == ' ') /* Convert first spaces to tab */
|
||||
{
|
||||
printf("0x%02x,", ('\t' ^ random()) & 0xFF);
|
||||
while ((c = getc(infile)) == ' ' && c != EOF);
|
||||
/* Drop the non-whitespace character through */
|
||||
linestart = NO;
|
||||
}
|
||||
switch(c)
|
||||
{
|
||||
case '\t':
|
||||
linestart = NO; /* Don't need to convert spaces */
|
||||
break;
|
||||
case '\n':
|
||||
linestart = YES; /* Ready to convert spaces again */
|
||||
break;
|
||||
}
|
||||
if (count++ % LINE == 0) /* Finished a line? */
|
||||
printf("\n\t");
|
||||
printf("0x%02x,", (c ^ random()) & 0xFF);
|
||||
}
|
||||
puts("\n\t0\n};");
|
||||
fclose(infile);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
void fatal(format, arg)
|
||||
char *format;
|
||||
{
|
||||
fprintf(stderr, format, arg);
|
||||
exit(1);
|
||||
}
|
828
games/adventure/subr.c
Normal file
828
games/adventure/subr.c
Normal file
@ -0,0 +1,828 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 "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(foo)
|
||||
{ register 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;
|
||||
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(foo)
|
||||
{ if ((cond[loc]%2)==0 && (prop[lamp]==0 || !here(lamp)))
|
||||
return(TRUE);
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
pct(n)
|
||||
int n;
|
||||
{ if (ran(100)<n) return(TRUE);
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
|
||||
fdwarf() /* 71 */
|
||||
{ register int i,j;
|
||||
register struct travlist *kk;
|
||||
|
||||
if (newloc!=loc&&!forced(loc)&&!bitset(loc,3))
|
||||
{ for (i=1; i<=5; i++)
|
||||
{ if (odloc[i]!=newloc||!dseen[i]) continue;
|
||||
newloc=loc;
|
||||
rspeak(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
loc=newloc; /* 74 */
|
||||
if (loc==0||forced(loc)||bitset(newloc,3)) return(2000);
|
||||
if (dflag==0)
|
||||
{ if (loc>=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;
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
return(2);
|
||||
}
|
||||
|
||||
bug(n)
|
||||
int n;
|
||||
{ printf("Please tell jim@rand.org that fatal bug %d happened.\n",n);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
checkhints() /* 2600 &c */
|
||||
{ register int hint;
|
||||
for (hint=4; hint<=hntmax; hint++)
|
||||
{ if (hinted[hint]) continue;
|
||||
if (!bitset(loc,hint)) hintlc[hint]= -1;
|
||||
hintlc[hint]++;
|
||||
if (hintlc[hint]<hints[hint][1]) continue;
|
||||
switch(hint)
|
||||
{ case 4: /* 40400 */
|
||||
if (prop[grate]==0&&!here(keys)) goto l40010;
|
||||
goto l40020;
|
||||
case 5: /* 40500 */
|
||||
if (here(bird)&&toting(rod)&&obj==bird) goto l40010;
|
||||
continue; /* i.e. goto l40030 */
|
||||
case 6: /* 40600 */
|
||||
if (here(snake)&&!here(bird)) goto l40010;
|
||||
goto l40020;
|
||||
case 7: /* 40700 */
|
||||
if (atloc[loc]==0&&atloc[oldloc]==0
|
||||
&& atloc[oldlc2]==0&&holdng>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;
|
||||
if (*wd2!=0) copystr(wd2,wd1);
|
||||
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;
|
||||
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(0)==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(0);
|
||||
if (obj==bottle && k!=0) place[k] = -1;
|
||||
return(2009);
|
||||
}
|
||||
|
||||
|
||||
dropper() /* 9021 */
|
||||
{ k=liq(0);
|
||||
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;
|
||||
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 (!weq(wd1,"y")&&!weq(wd1,"yes")) 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;
|
||||
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)!=0) spk=105;
|
||||
if (spk!=107) return(2011);
|
||||
prop[bottle]=((cond[loc]%4)/2)*2;
|
||||
k=liq(0);
|
||||
if (toting(bottle)) place[k]= -1;
|
||||
if (k==oil) spk=108;
|
||||
return(2011);
|
||||
}
|
||||
|
||||
|
||||
closing() /* 10000 */
|
||||
{ register 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;
|
||||
return(19999);
|
||||
}
|
||||
|
||||
|
||||
caveclose() /* 11000 */
|
||||
{ register 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;
|
||||
return(2);
|
||||
}
|
223
games/adventure/vocab.c
Normal file
223
games/adventure/vocab.c
Normal file
@ -0,0 +1,223 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 "hdr.h"
|
||||
|
||||
dstroy(object)
|
||||
int object;
|
||||
{ move(object,0);
|
||||
}
|
||||
|
||||
juggle(object)
|
||||
int object;
|
||||
{ register 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;
|
||||
|
||||
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;
|
||||
|
||||
if (object<=100)
|
||||
{ if (place[object]== -1) return;
|
||||
place[object] = -1;
|
||||
holdng++;
|
||||
}
|
||||
if (atloc[where]==object)
|
||||
{ atloc[where]=link[object];
|
||||
return;
|
||||
}
|
||||
for (temp=atloc[where]; link[temp]!=object; temp=link[temp]);
|
||||
link[temp]=link[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;
|
||||
link[object]=atloc[where];
|
||||
atloc[where]=object;
|
||||
}
|
||||
|
||||
|
||||
vocab(word,type,value) /* look up or store a word */
|
||||
char *word;
|
||||
int type; /* -2 for store, -1 for user word, >=0 for canned lookup*/
|
||||
int value; /* used for storing only */
|
||||
{ register int adr;
|
||||
register char *s,*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(length(word));
|
||||
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, length(word), 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)
|
||||
{ printf("Unable to find %s in vocab\n",word);
|
||||
exit(0);
|
||||
}
|
||||
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))
|
||||
{ printf("Hash table overflow\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
copystr(w1,w2) /* copy one string to another */
|
||||
char *w1,*w2;
|
||||
{ register char *s,*t;
|
||||
for (s=w1,t=w2; *s;)
|
||||
*t++ = *s++;
|
||||
*t=0;
|
||||
}
|
||||
|
||||
weq(w1,w2) /* compare words */
|
||||
char *w1,*w2; /* w1 is user, w2 is system */
|
||||
{ register char *s,*t;
|
||||
register int i;
|
||||
s=w1;
|
||||
t=w2;
|
||||
for (i=0; i<5; i++) /* compare at most 5 chars */
|
||||
{ if (*t==0 && *s==0)
|
||||
return(TRUE);
|
||||
if (*s++ != *t++) return(FALSE);
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
length(str) /* includes 0 at end */
|
||||
char *str;
|
||||
{ register char *s;
|
||||
register int n;
|
||||
for (n=0,s=str; *s++;) n++;
|
||||
return(n+1);
|
||||
}
|
||||
|
||||
prht() /* print hash table */
|
||||
{ register int i,j,l;
|
||||
char *c;
|
||||
struct hashtab *h;
|
||||
for (i=0; i<HTSIZE/10+1; i++)
|
||||
{ printf("%4d",i*10);
|
||||
for (j=0; j<10; j++)
|
||||
{ if (i*10+j>=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');
|
||||
}
|
||||
}
|
133
games/adventure/wizard.c
Normal file
133
games/adventure/wizard.c
Normal file
@ -0,0 +1,133 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 "hdr.h"
|
||||
|
||||
datime(d,t)
|
||||
int *d,*t;
|
||||
{ int tvec[2],*tptr;
|
||||
int *localtime();
|
||||
|
||||
time(tvec);
|
||||
tptr=localtime(tvec);
|
||||
*d=tptr[7]+365*(tptr[5]-77); /* day since 1977 (mod leap) */
|
||||
/* bug: this will overflow in the year 2066 AD */
|
||||
/* it will be attributed to Wm the C's millenial celebration */
|
||||
*t=tptr[2]*60+tptr[1]; /* and minutes since midnite */
|
||||
} /* pretty painless */
|
||||
|
||||
|
||||
char magic[6];
|
||||
|
||||
poof()
|
||||
{
|
||||
strcpy(magic, DECR(d,w,a,r,f));
|
||||
latncy = 45;
|
||||
}
|
||||
|
||||
Start(n)
|
||||
{ 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;
|
||||
char *word,*x;
|
||||
if (!yesm(16,0,7)) return(FALSE);
|
||||
mspeak(17);
|
||||
getin(&word,&x);
|
||||
if (!weq(word,magic))
|
||||
{ mspeak(20);
|
||||
return(FALSE);
|
||||
}
|
||||
mspeak(19);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
ciao(cmdfile)
|
||||
char *cmdfile;
|
||||
{ register char *c;
|
||||
register int outfd, size;
|
||||
char fname[80], buf[512];
|
||||
extern unsigned filesize;
|
||||
|
||||
printf("What would you like to call the saved version?\n");
|
||||
for (c=fname;; c++)
|
||||
if ((*c=getchar())=='\n') break;
|
||||
*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;
|
||||
{
|
||||
long rand(), i;
|
||||
|
||||
i = rand() % range;
|
||||
return(i);
|
||||
}
|
7
games/arithmetic/Makefile
Normal file
7
games/arithmetic/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
PROG= arithmetic
|
||||
MAN6= arithmetic.6
|
||||
HIDEGAME=hidegame
|
||||
|
||||
.include <bsd.prog.mk>
|
103
games/arithmetic/arithmetic.6
Normal file
103
games/arithmetic/arithmetic.6
Normal file
@ -0,0 +1,103 @@
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)arithmetic.6 8.1 (Berkeley) 5/31/93
|
||||
.\"
|
||||
.TH ARITHMETIC 6 "May 31, 1993"
|
||||
.UC 4
|
||||
.SH NAME
|
||||
arithmetic \- quiz on simple arithmetic
|
||||
.SH SYNOPSIS
|
||||
.B arithmetic
|
||||
.B [
|
||||
\-o +\-x/
|
||||
.B ]
|
||||
.B [
|
||||
\-r range
|
||||
.B ]
|
||||
.SH DESCRIPTION
|
||||
.I Arithmetic
|
||||
asks you to solve problems in simple arithmetic.
|
||||
Each question must be answered correctly before going on to the next.
|
||||
After every 20 problems, it prints the score so far and the time taken.
|
||||
You can quit at any time by typing the interrupt or end-of-file character.
|
||||
.PP
|
||||
The options are as follows:
|
||||
.TP
|
||||
\-o
|
||||
By default,
|
||||
.I arithmetic
|
||||
asks questions on addition of numbers from 0 to 10, and corresponding
|
||||
subtraction.
|
||||
By supplying one or more of the characters
|
||||
.BR +\-x/ ,
|
||||
you can ask for problems in addition, subtraction, multiplication, and
|
||||
division, respectively.
|
||||
If you give one of these characters more than once, that kind of problem
|
||||
will be asked correspondingly more often.
|
||||
.TP
|
||||
\-r
|
||||
If a
|
||||
.I range
|
||||
is supplied,
|
||||
.I arithmetic
|
||||
selects the numbers in its problems in the following way.
|
||||
For addition and multiplication, the numbers to be added or multiplied
|
||||
are between 0 and
|
||||
.IR range ,
|
||||
inclusive.
|
||||
For subtraction and division, both the required result and the number to
|
||||
divide by or subtract will be between 0 and
|
||||
.IR range .
|
||||
(Of course,
|
||||
.I arithmetic
|
||||
will not ask you to divide by 0.) The default
|
||||
.I range
|
||||
is 10.
|
||||
.PP
|
||||
When you get a problem wrong,
|
||||
.I arithmetic
|
||||
will remember the numbers involved, and will tend to select those numbers
|
||||
more often than others, in problems of the same sort.
|
||||
Eventually it will forgive and forget.
|
||||
.PP
|
||||
.I Arithmetic
|
||||
cannot be persuaded to tell you the right answer.
|
||||
You must work it out for yourself.
|
||||
.SH DIAGNOSTICS
|
||||
``What?'' if you get a question wrong.
|
||||
``Right!'' if you get it right.
|
||||
``Please type a number.'' if arithmetic doesn't understand what you typed.
|
||||
.SH "SEE ALSO"
|
||||
bc(1), dc(1)
|
374
games/arithmetic/arithmetic.c
Normal file
374
games/arithmetic/arithmetic.c
Normal file
@ -0,0 +1,374 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 <emcmanus@cs.tcd.ie>.
|
||||
*
|
||||
* 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 <sys/types.h>
|
||||
#include <sys/signal.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char keylist[] = "+-x/";
|
||||
char defaultkeys[] = "+-";
|
||||
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.
|
||||
*/
|
||||
void
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
int ch, cnt;
|
||||
void intr();
|
||||
|
||||
while ((ch = getopt(argc, argv, "r:o:")) != EOF)
|
||||
switch(ch) {
|
||||
case 'o': {
|
||||
register 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. */
|
||||
srandom((int)time((time_t *)NULL));
|
||||
|
||||
(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;
|
||||
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;
|
||||
char *malloc();
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
4
games/atc/BUGS
Normal file
4
games/atc/BUGS
Normal file
@ -0,0 +1,4 @@
|
||||
log restarts if interrupted
|
||||
Still refreshes after exit
|
||||
Should ^Z be disabled?
|
||||
does not exit after hup
|
18
games/atc/Makefile
Normal file
18
games/atc/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
PROG= atc
|
||||
CFLAGS+=-DBSD -I${.CURDIR} -I.
|
||||
SRCS= extern.c grammar.c graphics.c input.c lex.c list.c log.c \
|
||||
main.c tunable.c update.c
|
||||
MAN6= atc.6
|
||||
DPADD= ${usr/lib/libl.a ${LIBM} ${LIBTERM} ${LIBCURSES} ${LIBCOMPAT}
|
||||
LDADD= -ll -lm -lcurses -ltermcap -lcompat
|
||||
GAMES= ATC_scores Game_List Killer crossover default easy game_2
|
||||
CLEANFILES=grammar.c y.tab.h lex.c
|
||||
HIDEGAME=hidegame
|
||||
|
||||
beforeinstall:
|
||||
(cd ${.CURDIR}/games; install -c -o ${BINOWN} -g ${BINGRP} -m 400 \
|
||||
${GAMES} ${DESTDIR}/usr/share/games/atc)
|
||||
|
||||
.include <bsd.prog.mk>
|
598
games/atc/atc.6
Normal file
598
games/atc/atc.6
Normal file
@ -0,0 +1,598 @@
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)atc.6 8.1 (Berkeley) 5/31/93
|
||||
.\"
|
||||
. \" XP - exdented paragraph
|
||||
.de XP
|
||||
.RT
|
||||
.if \\n(1T .sp \\n(PDu
|
||||
.ne 1.1
|
||||
.if !\\n(IP .nr IP +1
|
||||
.in +\\n(I\\n(IRu
|
||||
.ti -\\n(I\\n(IRu
|
||||
..
|
||||
.\" Copyright (c) 1986 Ed James. All rights reserved.
|
||||
.\"
|
||||
.TH ATC 6 "May 31, 1993"
|
||||
.UC
|
||||
.SH NAME
|
||||
atc \- air traffic controller game
|
||||
.SH SYNOPSIS
|
||||
.B atc
|
||||
-[u?lstp] [-[gf] game_name] [-r random seed]
|
||||
.SH DESCRIPTION
|
||||
.LP
|
||||
.I Atc
|
||||
lets you try your hand at the nerve wracking duties of the air traffic
|
||||
controller without endangering the lives of millions of
|
||||
travelers each year.
|
||||
Your responsibilities require you to direct the flight of jets
|
||||
and prop planes into and out of the flight arena and airports.
|
||||
The speed (update time) and frequency of the planes depend on the
|
||||
difficulty of the chosen arena.
|
||||
.SH OPTIONS
|
||||
.LP
|
||||
.TP 8
|
||||
.B \-u
|
||||
Print the usage line and exit.
|
||||
.TP
|
||||
.B \-?
|
||||
Same as
|
||||
.B \-u.
|
||||
.TP
|
||||
.B \-l
|
||||
Print a list of available games and exit.
|
||||
The first game name printed is the default game.
|
||||
.TP
|
||||
.B \-s
|
||||
Print the score list (formerly the Top Ten list).
|
||||
.TP
|
||||
.B \-t
|
||||
Same as
|
||||
.B \-s.
|
||||
.TP
|
||||
.B \-p
|
||||
Print the path to the special directory where
|
||||
.I atc
|
||||
expects to find its private files. This is used during the
|
||||
installation of the program.
|
||||
.TP
|
||||
.B "\-g game"
|
||||
Play the named game. If the game listed is not one of the
|
||||
ones printed from the
|
||||
.B \-l
|
||||
option, the default game is played.
|
||||
.TP
|
||||
.B "\-f game"
|
||||
Same as
|
||||
.B \-g.
|
||||
.TP
|
||||
.B "\-r seed"
|
||||
Set the random seed. The purpose of this flag is questionable.
|
||||
.SH GOALS
|
||||
.LP
|
||||
Your goal in
|
||||
.I atc
|
||||
is to keep the game going as long as possible.
|
||||
There is no winning state, except to beat the times of other players.
|
||||
You will need to: launch planes at airports (by instructing them to
|
||||
increase their altitude); land planes at airports (by instructing them to
|
||||
go to altitude zero when exactly over the airport); and maneuver planes
|
||||
out of exit points.
|
||||
.LP
|
||||
Several things will cause the end of the game.
|
||||
Each plane has a destination (see information area), and
|
||||
sending a plane to the wrong destination is an error.
|
||||
Planes can run out of fuel, or can collide. Collision is defined as
|
||||
adjacency in any of the three dimensions. A plane leaving the arena
|
||||
in any other way than through its destination exit is an error as well.
|
||||
.LP
|
||||
Scores are sorted in order of the number of planes safe. The other
|
||||
statistics are provided merely for fun. There is no penalty for
|
||||
taking longer than another player (except in the case of ties).
|
||||
.LP
|
||||
Suspending a game is not permitted. If you get a talk message, tough.
|
||||
When was the last time an Air Traffic Controller got called away to
|
||||
the phone?
|
||||
.SH "THE DISPLAY"
|
||||
.LP
|
||||
Depending on the terminal you run
|
||||
.I atc
|
||||
on, the screen will be divided into 4 areas.
|
||||
It should be stressed that the terminal driver portion of the
|
||||
game was designed to be reconfigurable, so the display format can vary
|
||||
depending the version you are playing. The descriptions here are based
|
||||
on the ascii version
|
||||
of the game. The game rules and input format, however,
|
||||
should remain consistent.
|
||||
Control-L redraws the screen, should it become muddled.
|
||||
.SS RADAR
|
||||
.IP
|
||||
The first screen area is the radar display, showing the relative locations
|
||||
of the planes, airports, standard entry/exit points, radar
|
||||
beacons, and "lines" which simply serve to aid you in guiding
|
||||
the planes.
|
||||
.IP
|
||||
Planes are shown as a single letter with an altitude. If
|
||||
the numerical altitude is a single digit, then it represents
|
||||
thousands of feet.
|
||||
Some distinction is made between the prop
|
||||
planes and the jets. On ascii terminals, prop planes are
|
||||
represented by a upper case letter, jets by a lower case letter.
|
||||
.IP
|
||||
Airports are shown as a number and some indication of the direction
|
||||
planes must be going to land at the airport.
|
||||
On ascii terminals, this is one of '^', '>', '<', and 'v', to indicate
|
||||
north (0 degrees), east (90), west (270) and south (180), respectively.
|
||||
The planes will also
|
||||
take off in this direction.
|
||||
.IP
|
||||
Beacons are represented as circles or asterisks and a number.
|
||||
Their purpose is to offer a place of easy reference to the plane pilots.
|
||||
See 'the delay command' under the input section of this manual.
|
||||
.IP
|
||||
Entry/exit points are displayed as numbers along the border of the
|
||||
radar screen. Planes will enter the arena from these points without
|
||||
warning. These points have a direction associated with them, and
|
||||
planes will always enter the arena from this direction. On the
|
||||
ascii version of
|
||||
.I atc,
|
||||
this direction is not displayed. It will become apparent
|
||||
what this direction is as the game progresses.
|
||||
.IP
|
||||
Incoming planes will always enter at the same altitude: 7000 feet.
|
||||
For a plane to successfully depart through an entry/exit point,
|
||||
it must be flying at 9000 feet.
|
||||
It is not necessary for the planes to be flying in any particular
|
||||
direction when they leave the arena (yet).
|
||||
.SS "INFORMATION AREA"
|
||||
.IP
|
||||
The second area of the display is the information area, which lists
|
||||
the time (number of updates since start), and the number of planes you
|
||||
have directed safely out of the arena.
|
||||
Below this is a list of planes currently in the air, followed by a
|
||||
blank line, and then a list of planes on the ground (at airports).
|
||||
Each line lists the plane name and its current altitude,
|
||||
an optional asterisk indicating low fuel, the plane's destination,
|
||||
and the plane's current command. Changing altitude is not considered
|
||||
to be a command and is therefore not displayed. The following are
|
||||
some possible information lines:
|
||||
.IP
|
||||
B4*A0: Circle @ b1
|
||||
.br
|
||||
g7 E4: 225
|
||||
.IP
|
||||
The first example shows a prop plane named 'B' that is flying at 4000
|
||||
feet. It is low on fuel (note the '*'). It's destination is
|
||||
Airport #0.
|
||||
The next command it expects
|
||||
to do is circle when it reaches Beacon #1.
|
||||
The second example shows a jet named 'g' at 7000 feet, destined for
|
||||
Exit #4. It is just now executing a turn to 225 degrees (South-West).
|
||||
.SS "INPUT AREA"
|
||||
.IP
|
||||
The third area of the display is the input area. It is here that
|
||||
your input is reflected. See the INPUT heading of this manual
|
||||
for more details.
|
||||
.SS "AUTHOR AREA"
|
||||
.IP
|
||||
This area is used simply to give credit where credit is due. :-)
|
||||
.SH INPUT
|
||||
.LP
|
||||
A command completion interface is built into
|
||||
the game. At any time, typing '?' will list possible input characters.
|
||||
Typing a backspace (your erase character) backs up, erasing the last part
|
||||
of the command. When a command is complete, a return enters it, and
|
||||
any semantic checking is done at that time. If no errors are detected,
|
||||
the command is sent to the appropriate plane. If an error is discovered
|
||||
during the check, the offending statement will be underscored and a
|
||||
(hopefully) descriptive message will be printed under it.
|
||||
.LP
|
||||
The command syntax is broken into two parts:
|
||||
.I "Immediate Only"
|
||||
and
|
||||
.I Delayable
|
||||
commands.
|
||||
.I "Immediate Only"
|
||||
commands happen on the next
|
||||
update.
|
||||
.I Delayable
|
||||
commands also happen on the next update unless they
|
||||
are followed by an optional predicate called the
|
||||
.I Delay
|
||||
command.
|
||||
.LP
|
||||
In the following tables, the syntax
|
||||
.B [0\-9]
|
||||
means any single digit, and
|
||||
.B <dir>
|
||||
refers to the keys around the 's' key, namely ``wedcxzaq''.
|
||||
In absolute references, 'q' refers to North-West or 315 degrees, and 'w'
|
||||
refers to North, or 0 degrees.
|
||||
In relative references, 'q' refers to -45 degrees or 45 degrees left, and 'w'
|
||||
refers to 0 degrees, or no change in direction.
|
||||
.LP
|
||||
All commands start with a plane letter. This indicates the recipient
|
||||
of the command. Case is ignored.
|
||||
.SS "IMMEDIATE ONLY COMMANDS"
|
||||
.RS
|
||||
.B "\- a Altitude:"
|
||||
.RS
|
||||
Affect a plane's altitude (and take off).
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0\-9] Number:"
|
||||
.RS
|
||||
Go to the given altitude (thousands of feet).
|
||||
.RE
|
||||
.B "\- c/+ Climb:"
|
||||
.RS
|
||||
Relative altitude change.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0\-9] Number:"
|
||||
.RS
|
||||
Difference in thousands of feet.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- d/\- Descend:"
|
||||
.RS
|
||||
Relative altitude change.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0\-9] Number:"
|
||||
.RS
|
||||
Difference in thousands of feet.
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.B "\- m Mark:"
|
||||
.RS
|
||||
Display in highlighted mode. Command is displayed normally.
|
||||
.RE
|
||||
.B "\- i Ignore:"
|
||||
.RS
|
||||
Do not display highlighted. Command is displayed as a
|
||||
line of dashes if there is no command.
|
||||
.RE
|
||||
.B "\- u Unmark:"
|
||||
.RS
|
||||
Same as ignore, but if a delayed command is processed,
|
||||
the plane will become marked. This is useful if you want
|
||||
to forget about a plane during part, but not all, of its
|
||||
journey.
|
||||
.RE
|
||||
.RE
|
||||
.SS "DELAYABLE COMMANDS"
|
||||
.RS
|
||||
.B "\- c Circle:"
|
||||
.RS
|
||||
Have the plane circle (clockwise by default).
|
||||
.RE
|
||||
.RS
|
||||
.B "\- l Left:"
|
||||
.RS
|
||||
Circle counterclockwise.
|
||||
.RE
|
||||
.B "\- r Right:"
|
||||
.RS
|
||||
Circle clockwise.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- t Turn:"
|
||||
.RS
|
||||
Change direction.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- l Left:"
|
||||
.RS
|
||||
Turn counterclockwise (45 degrees by default).
|
||||
.RE
|
||||
.RS
|
||||
.B "\- <dir> Direction:"
|
||||
.RS
|
||||
Turn ccw the given number of degrees.
|
||||
Zero degrees is no turn. A ccw turn
|
||||
of -45 degrees is 45 cw.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- r Right:"
|
||||
.RS
|
||||
Turn clockwise (45 degrees by default).
|
||||
.RE
|
||||
.RS
|
||||
.B "\- <dir> Direction:"
|
||||
.RS
|
||||
Same as turn left <dir>.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- L Left 90:"
|
||||
.RS
|
||||
Turn counterclockwise 90 degrees.
|
||||
.RE
|
||||
.B "\- R Right 90:"
|
||||
.RS
|
||||
Turn clockwise 90 degrees.
|
||||
.RE
|
||||
.B "\- <dir> Direction:"
|
||||
.RS
|
||||
Turn to the absolute compass heading given.
|
||||
The shortest turn will be taken.
|
||||
.RE
|
||||
.B "\- t Towards:"
|
||||
.RS
|
||||
Turn towards a beacon, airport or exit. The turn is
|
||||
just an estimate.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- b/* Beacon:"
|
||||
.RS
|
||||
Turn towards the beacon.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0-9] Number:"
|
||||
.RS
|
||||
The beacon number.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- e Exit:"
|
||||
.RS
|
||||
Turn towards the exit.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0-9] Number:"
|
||||
.RS
|
||||
The exit number.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- a Airport:"
|
||||
.RS
|
||||
Turn towards the airport.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0-9] Number:"
|
||||
.RS
|
||||
The airport number.
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.SS THE DELAY COMMAND
|
||||
.LP
|
||||
The
|
||||
.B Delay
|
||||
(a/@)
|
||||
command may be appended to any
|
||||
.B Delayable
|
||||
command. It allows the controller to instruct a plane to do an action
|
||||
when the plane reaches a particular beacon (or other objects in future
|
||||
versions).
|
||||
.sp
|
||||
.RS
|
||||
.B "\- a/@ At:"
|
||||
.RS
|
||||
Do the given delayable command when the plane reaches the given beacon.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- b/* Beacon:"
|
||||
.RS
|
||||
This is redundant to allow for expansion.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0-9] Number:"
|
||||
.RS
|
||||
The beacon number.
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.SS "MARKING, UNMARKING AND IGNORING"
|
||||
.LP
|
||||
Planes are
|
||||
.B marked
|
||||
when they enter the arena. This means they are displayed in highlighted
|
||||
mode on the radar display. A plane may also be either
|
||||
.B unmarked
|
||||
or
|
||||
.B ignored.
|
||||
An
|
||||
.B unmarked
|
||||
plane is drawn in unhighlighted mode, and a line of dashes is displayed in
|
||||
the command field of the information area. The plane will remain this
|
||||
way until a mark command has been issued. Any other command will be issued,
|
||||
but the command line will return to a line of dashes when the command
|
||||
is completed.
|
||||
.LP
|
||||
An
|
||||
.B ignored
|
||||
plane is treated the same as an unmarked plane, except that it will
|
||||
automatically switch to
|
||||
.B marked
|
||||
status when a delayed command has been processed. This is useful if
|
||||
you want to forget about a plane for a while, but its flight path has
|
||||
not yet been completely set.
|
||||
.LP
|
||||
As with all of the commands, marking, unmarking and ignoring will take effect
|
||||
at the beginning of the next update. Do not be surprised if the plane does
|
||||
not immediately switch to unhighlighted mode.
|
||||
.SS EXAMPLES
|
||||
.RS
|
||||
.TP 16
|
||||
atlab1
|
||||
a: turn left at beacon #1
|
||||
.TP 16
|
||||
cc
|
||||
C: circle
|
||||
.TP 16
|
||||
gtte4ab2
|
||||
g: turn towards exit #4 at beacon #2
|
||||
.TP 16
|
||||
ma+2
|
||||
m: altitude: climb 2000 feet
|
||||
.TP 16
|
||||
stq
|
||||
S: turn to 315
|
||||
.TP 16
|
||||
xi
|
||||
x: ignore
|
||||
.RE
|
||||
.SH "OTHER INFORMATION"
|
||||
.LP
|
||||
Jets move every update; prop planes move every other update.
|
||||
.LP
|
||||
All planes turn a most 90 degrees per movement.
|
||||
.LP
|
||||
Planes enter at 7000 feet and leave at 9000 feet.
|
||||
.LP
|
||||
Planes flying at an altitude of 0 crash if they are not over an airport.
|
||||
.LP
|
||||
Planes waiting at airports can only be told to take off (climb in altitude).
|
||||
.SH "NEW GAMES"
|
||||
.LP
|
||||
The
|
||||
.B Game_List
|
||||
file lists the currently available play fields. New field description
|
||||
file names must be placed in this file to be 'playable'. If a player
|
||||
specifies a game not in this file, his score will not be logged.
|
||||
.LP
|
||||
The game field description files are broken into two parts. The first
|
||||
part is the definition section. Here, the four tunable game parameters
|
||||
must be set. These variables are set with the syntax:
|
||||
.IP
|
||||
variable = number;
|
||||
.LP
|
||||
Variable may be one of:
|
||||
.B update,
|
||||
indicating the number of seconds between forced updates;
|
||||
.B newplane,
|
||||
indicating (about) the number of updates between new plane entries;
|
||||
.B width,
|
||||
indicating the width of the play field; and
|
||||
.B height,
|
||||
indicating the height of the play field.
|
||||
.LP
|
||||
The second part of the field description files describes the locations
|
||||
of the exits, the beacons, the airports and the lines.
|
||||
The syntax is as follows:
|
||||
.IP
|
||||
beacon: (x y) ... ;
|
||||
.br
|
||||
airport: (x y direction) ... ;
|
||||
.br
|
||||
exit: (x y direction) ... ;
|
||||
.br
|
||||
line: [ (x1 y1) (x2 y2) ] ... ;
|
||||
.LP
|
||||
For beacons, a simple x, y coordinate pair is used (enclosed in parenthesis).
|
||||
Airports and exits require a third value, a direction, which is one
|
||||
of
|
||||
.B wedcxzaq.
|
||||
For airports, this is the direction that planes must be going to take
|
||||
off and land, and for exits, this is the direction that planes will going
|
||||
when they
|
||||
.B enter
|
||||
the arena. This may not seem intuitive, but as there is no restriction on
|
||||
direction of exit, this is appropriate.
|
||||
Lines are slightly different, since they need two coordinate pairs to
|
||||
specify the line endpoints. These endpoints must be enclosed in
|
||||
square brackets.
|
||||
.LP
|
||||
All statements are semi-colon (;) terminated. Multiple item statements
|
||||
accumulate. Each definition must occur exactly once, before any
|
||||
item statements. Comments begin with a hash (#) symbol
|
||||
and terminate with a newline.
|
||||
The coordinates are between zero and width-1 and height-1
|
||||
inclusive. All of the exit coordinates must lie on the borders, and
|
||||
all of the beacons and airports must lie inside of the borders.
|
||||
Line endpoints may be anywhere within the field, so long as
|
||||
the lines are horizontal, vertical or
|
||||
.B "exactly diagonal."
|
||||
.SS "FIELD FILE EXAMPLE"
|
||||
.RS
|
||||
.sp
|
||||
.nf
|
||||
.TA 1i 1i
|
||||
.ta 1i 1i
|
||||
# This is the default game.
|
||||
|
||||
update = 5;
|
||||
newplane = 5;
|
||||
width = 30;
|
||||
height = 21;
|
||||
|
||||
exit: ( 12 0 x ) ( 29 0 z ) ( 29 7 a ) ( 29 17 a )
|
||||
( 9 20 e ) ( 0 13 d ) ( 0 7 d ) ( 0 0 c ) ;
|
||||
|
||||
beacon: ( 12 7 ) ( 12 17 ) ;
|
||||
|
||||
airport: ( 20 15 w ) ( 20 18 d ) ;
|
||||
|
||||
line: [ ( 1 1 ) ( 6 6 ) ]
|
||||
[ ( 12 1 ) ( 12 6 ) ]
|
||||
[ ( 13 7 ) ( 28 7 ) ]
|
||||
[ ( 28 1 ) ( 13 16 ) ]
|
||||
[ ( 1 13 ) ( 11 13 ) ]
|
||||
[ ( 12 8 ) ( 12 16 ) ]
|
||||
[ ( 11 18 ) ( 10 19 ) ]
|
||||
[ ( 13 17 ) ( 28 17 ) ]
|
||||
[ ( 1 7 ) ( 11 7 ) ] ;
|
||||
.fi
|
||||
.RE
|
||||
.SH FILES
|
||||
.LP
|
||||
Files are kept in a special directory. See the OPTIONS for a way to
|
||||
print this path out.
|
||||
.TP 16
|
||||
.B ATC_score
|
||||
Where the scores are kept.
|
||||
.TP 16
|
||||
.B Game_List
|
||||
The list of playable games.
|
||||
.SH AUTHOR
|
||||
.LP
|
||||
Ed James, UC Berkeley: edjames@ucbvax.berkeley.edu, ucbvax!edjames
|
||||
.LP
|
||||
This game is based on someone's description of the overall flavor
|
||||
of a game written for some unknown PC many years ago, maybe.
|
||||
.SH BUGS
|
||||
.LP
|
||||
The screen sometimes refreshes after you have quit.
|
||||
.LP
|
||||
Yet Another Curses Bug was discovered during the development of this game.
|
||||
If your curses library clrtobot.o is version 5.1 or earlier,
|
||||
you will have erase problems with the backspace operator in the input
|
||||
window.
|
||||
|
80
games/atc/def.h
Normal file
80
games/atc/def.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*-
|
||||
* 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.
|
||||
*
|
||||
* @(#)def.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define AUTHOR_STR "ATC - by Ed James"
|
||||
|
||||
#define PI 3.14159654
|
||||
|
||||
#define LOWFUEL 15
|
||||
|
||||
#define REALLOC 10
|
||||
|
||||
#define SGN(x) ((x < 0) ? -1 : ((x > 0) ? 1 : 0))
|
||||
#define ABS(x) ((x < 0) ? -(x) : (x))
|
||||
#define DIR_FROM_DXDY(dx,dy) ((int) (atan2((double)(dy), (double)(dx)) \
|
||||
* MAXDIR / (2 * PI) + 2.5 + MAXDIR) % MAXDIR)
|
||||
|
||||
#define MAXDIR 8
|
||||
|
||||
#define D_LEFT 1
|
||||
#define D_RIGHT 2
|
||||
#define D_UP 3
|
||||
#define D_DOWN 4
|
||||
|
||||
#define T_NODEST 0
|
||||
#define T_BEACON 1
|
||||
#define T_EXIT 2
|
||||
#define T_AIRPORT 3
|
||||
|
||||
#define S_NONE 0
|
||||
#define S_GONE 1
|
||||
#define S_MARKED 2
|
||||
#define S_UNMARKED 3
|
||||
#define S_IGNORED 4
|
||||
|
||||
#define INPUT_LINES 3
|
||||
#define PLANE_COLS 20
|
75
games/atc/extern.c
Normal file
75
games/atc/extern.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "include.h"
|
||||
|
||||
char GAMES[] = "Game_List";
|
||||
|
||||
int clck, safe_planes, start_time, test_mode;
|
||||
|
||||
char *file;
|
||||
|
||||
FILE *filein, *fileout;
|
||||
|
||||
C_SCREEN screen, *sp = &screen;
|
||||
|
||||
LIST air, ground;
|
||||
|
||||
struct sgttyb tty_start, tty_new;
|
||||
|
||||
DISPLACEMENT displacement[MAXDIR] = {
|
||||
{ 0, -1 },
|
||||
{ 1, -1 },
|
||||
{ 1, 0 },
|
||||
{ 1, 1 },
|
||||
{ 0, 1 },
|
||||
{ -1, 1 },
|
||||
{ -1, 0 },
|
||||
{ -1, -1 }
|
||||
};
|
62
games/atc/extern.h
Normal file
62
games/atc/extern.h
Normal file
@ -0,0 +1,62 @@
|
||||
/*-
|
||||
* 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.
|
||||
*
|
||||
* @(#)extern.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
extern char GAMES[], *file;
|
||||
|
||||
extern int clck, safe_planes, start_time, test_mode;
|
||||
|
||||
extern FILE *filein, *fileout;
|
||||
|
||||
extern C_SCREEN screen, *sp;
|
||||
|
||||
extern LIST air, ground;
|
||||
|
||||
extern struct sgttyb tty_start, tty_new;
|
||||
|
||||
extern DISPLACEMENT displacement[MAXDIR];
|
||||
|
||||
extern PLANE *findplane(), *newplane();
|
5
games/atc/games/ATC_scores
Normal file
5
games/atc/games/ATC_scores
Normal file
@ -0,0 +1,5 @@
|
||||
schumann puff game_2 171 1414 195
|
||||
schumann puff default 18 220 59
|
||||
schumann puff easy 13 182 146
|
||||
schumann puff crossover 11 74 448
|
||||
schumann puff Killer 0 38 27
|
5
games/atc/games/Game_List
Normal file
5
games/atc/games/Game_List
Normal file
@ -0,0 +1,5 @@
|
||||
default
|
||||
easy
|
||||
crossover
|
||||
Killer
|
||||
game_2
|
21
games/atc/games/Killer
Normal file
21
games/atc/games/Killer
Normal file
@ -0,0 +1,21 @@
|
||||
update = 1;
|
||||
newplane = 4;
|
||||
width = 30;
|
||||
height = 21;
|
||||
|
||||
exit: ( 29 7 a ) ( 29 17 a )
|
||||
( 0 7 d ) ( 0 0 c ) ;
|
||||
|
||||
beacon: ( 12 7 ) ( 12 17 ) ( 14 10 ) ( 20 15 ) ;
|
||||
|
||||
airport: ( 20 18 d ) ;
|
||||
|
||||
line: [ ( 1 1 ) ( 6 6 ) ]
|
||||
[ ( 12 1 ) ( 12 6 ) ]
|
||||
[ ( 13 7 ) ( 28 7 ) ]
|
||||
[ ( 28 1 ) ( 13 16 ) ]
|
||||
[ ( 1 13 ) ( 11 13 ) ]
|
||||
[ ( 12 8 ) ( 12 16 ) ]
|
||||
[ ( 11 18 ) ( 10 19 ) ]
|
||||
[ ( 13 17 ) ( 28 17 ) ]
|
||||
[ ( 1 7 ) ( 11 7 ) ] ;
|
14
games/atc/games/crossover
Normal file
14
games/atc/games/crossover
Normal file
@ -0,0 +1,14 @@
|
||||
update = 5;
|
||||
newplane = 5;
|
||||
width = 29;
|
||||
height = 21;
|
||||
|
||||
exit: ( 0 0 c ) ( 8 0 c ) ( 20 0 z ) ( 28 0 z )
|
||||
( 28 20 q ) ( 20 20 q ) ( 8 20 e ) ( 0 20 e );
|
||||
|
||||
beacon: ( 14 6 ) ( 18 10 ) ( 14 14 ) ( 10 10 );
|
||||
|
||||
line: [ ( 0 0 ) ( 20 20 ) ]
|
||||
[ ( 8 0 ) ( 28 20 ) ]
|
||||
[ ( 20 0 ) ( 0 20 ) ]
|
||||
[ ( 28 0 ) ( 8 20 ) ];
|
21
games/atc/games/default
Normal file
21
games/atc/games/default
Normal file
@ -0,0 +1,21 @@
|
||||
update = 5;
|
||||
newplane = 10;
|
||||
width = 30;
|
||||
height = 21;
|
||||
|
||||
exit: ( 12 0 x ) ( 29 0 z ) ( 29 7 a ) ( 29 17 a )
|
||||
( 9 20 e ) ( 0 13 d ) ( 0 7 d ) ( 0 0 c ) ;
|
||||
|
||||
beacon: ( 12 7 ) ( 12 17 ) ;
|
||||
|
||||
airport: ( 20 15 w ) ( 20 18 d ) ;
|
||||
|
||||
line: [ ( 1 1 ) ( 6 6 ) ]
|
||||
[ ( 12 1 ) ( 12 6 ) ]
|
||||
[ ( 13 7 ) ( 28 7 ) ]
|
||||
[ ( 28 1 ) ( 13 16 ) ]
|
||||
[ ( 1 13 ) ( 11 13 ) ]
|
||||
[ ( 12 8 ) ( 12 16 ) ]
|
||||
[ ( 11 18 ) ( 10 19 ) ]
|
||||
[ ( 13 17 ) ( 28 17 ) ]
|
||||
[ ( 1 7 ) ( 11 7 ) ] ;
|
15
games/atc/games/easy
Normal file
15
games/atc/games/easy
Normal file
@ -0,0 +1,15 @@
|
||||
update = 7;
|
||||
newplane = 12;
|
||||
width = 15;
|
||||
height = 15;
|
||||
|
||||
exit: ( 7 0 x ) ( 14 0 z ) ( 12 14 q ) ( 0 14 e ) ;
|
||||
|
||||
beacon: ( 12 7 ) ;
|
||||
|
||||
airport: ( 7 8 w ) ;
|
||||
|
||||
line: [ ( 1 1 ) ( 6 6 ) ]
|
||||
[ ( 7 9 ) ( 12 14 ) ]
|
||||
[ ( 7 0 ) ( 7 14 ) ]
|
||||
[ ( 1 7 ) ( 11 7 ) ] ;
|
22
games/atc/games/game_2
Normal file
22
games/atc/games/game_2
Normal file
@ -0,0 +1,22 @@
|
||||
update = 5;
|
||||
newplane = 8;
|
||||
width = 30;
|
||||
height = 21;
|
||||
|
||||
exit: ( 12 0 x ) ( 29 0 z ) ( 29 6 a ) ( 29 13 a )
|
||||
( 9 20 e ) ( 0 13 d ) ( 0 6 d ) ( 0 0 c ) ;
|
||||
|
||||
beacon: ( 12 17 ) ( 23 6 ) ( 23 13 ) ( 25 17 )
|
||||
( 12 6 ) ( 12 13 ) ( 6 6 ) ;
|
||||
|
||||
airport: ( 18 17 d ) ;
|
||||
|
||||
line: [ ( 1 1 ) ( 16 16 ) ]
|
||||
[ ( 1 6 ) ( 28 6 ) ]
|
||||
[ ( 12 1 ) ( 12 17 ) ]
|
||||
[ ( 10 19 ) ( 28 1 ) ]
|
||||
[ ( 13 17 ) ( 17 17 ) ]
|
||||
[ ( 1 13 ) ( 28 13 ) ]
|
||||
[ ( 19 17 ) ( 24 17 ) ]
|
||||
[ ( 19 17 ) ( 22 14 ) ]
|
||||
[ ( 26 16 ) ( 28 14 ) ] ;
|
389
games/atc/grammar.y
Normal file
389
games/atc/grammar.y
Normal file
@ -0,0 +1,389 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
%token <ival> HeightOp
|
||||
%token <ival> WidthOp
|
||||
%token <ival> UpdateOp
|
||||
%token <ival> NewplaneOp
|
||||
%token <cval> DirOp
|
||||
%token <ival> ConstOp
|
||||
%token <ival> LineOp
|
||||
%token <ival> AirportOp
|
||||
%token <ival> BeaconOp
|
||||
%token <ival> ExitOp
|
||||
%union {
|
||||
int ival;
|
||||
char cval;
|
||||
}
|
||||
|
||||
%{
|
||||
#include "include.h"
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)grammar.y 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
int errors = 0;
|
||||
int line = 1;
|
||||
%}
|
||||
|
||||
%%
|
||||
file:
|
||||
bunch_of_defs { if (checkdefs() < 0) return (errors); } bunch_of_lines
|
||||
{
|
||||
if (sp->num_exits + sp->num_airports < 2)
|
||||
yyerror("Need at least 2 airports and/or exits.");
|
||||
return (errors);
|
||||
}
|
||||
;
|
||||
|
||||
bunch_of_defs:
|
||||
def bunch_of_defs
|
||||
| def
|
||||
;
|
||||
|
||||
def:
|
||||
udef
|
||||
| ndef
|
||||
| wdef
|
||||
| hdef
|
||||
;
|
||||
|
||||
udef:
|
||||
UpdateOp '=' ConstOp ';'
|
||||
{
|
||||
if (sp->update_secs != 0)
|
||||
return (yyerror("Redefinition of 'update'."));
|
||||
else if ($3 < 1)
|
||||
return (yyerror("'update' is too small."));
|
||||
else
|
||||
sp->update_secs = $3;
|
||||
}
|
||||
;
|
||||
|
||||
ndef:
|
||||
NewplaneOp '=' ConstOp ';'
|
||||
{
|
||||
if (sp->newplane_time != 0)
|
||||
return (yyerror("Redefinition of 'newplane'."));
|
||||
else if ($3 < 1)
|
||||
return (yyerror("'newplane' is too small."));
|
||||
else
|
||||
sp->newplane_time = $3;
|
||||
}
|
||||
;
|
||||
|
||||
hdef:
|
||||
HeightOp '=' ConstOp ';'
|
||||
{
|
||||
if (sp->height != 0)
|
||||
return (yyerror("Redefinition of 'height'."));
|
||||
else if ($3 < 3)
|
||||
return (yyerror("'height' is too small."));
|
||||
else
|
||||
sp->height = $3;
|
||||
}
|
||||
;
|
||||
|
||||
wdef:
|
||||
WidthOp '=' ConstOp ';'
|
||||
{
|
||||
if (sp->height != 0)
|
||||
return (yyerror("Redefinition of 'width'."));
|
||||
else if ($3 < 3)
|
||||
return (yyerror("'width' is too small."));
|
||||
else
|
||||
sp->width = $3;
|
||||
}
|
||||
;
|
||||
|
||||
bunch_of_lines:
|
||||
line bunch_of_lines
|
||||
{}
|
||||
| line
|
||||
{}
|
||||
;
|
||||
|
||||
line:
|
||||
BeaconOp ':' Bpoint_list ';'
|
||||
{}
|
||||
| ExitOp ':' Epoint_list ';'
|
||||
{}
|
||||
| LineOp ':' Lline_list ';'
|
||||
{}
|
||||
| AirportOp ':' Apoint_list ';'
|
||||
{}
|
||||
;
|
||||
|
||||
Bpoint_list:
|
||||
Bpoint Bpoint_list
|
||||
{}
|
||||
| Bpoint
|
||||
{}
|
||||
;
|
||||
|
||||
Bpoint:
|
||||
'(' ConstOp ConstOp ')'
|
||||
{
|
||||
if (sp->num_beacons % REALLOC == 0) {
|
||||
if (sp->beacon == NULL)
|
||||
sp->beacon = (BEACON *) malloc((sp->num_beacons
|
||||
+ REALLOC) * sizeof (BEACON));
|
||||
else
|
||||
sp->beacon = (BEACON *) realloc(sp->beacon,
|
||||
(sp->num_beacons + REALLOC) *
|
||||
sizeof (BEACON));
|
||||
if (sp->beacon == NULL)
|
||||
return (yyerror("No memory available."));
|
||||
}
|
||||
sp->beacon[sp->num_beacons].x = $2;
|
||||
sp->beacon[sp->num_beacons].y = $3;
|
||||
check_point($2, $3);
|
||||
sp->num_beacons++;
|
||||
}
|
||||
;
|
||||
|
||||
Epoint_list:
|
||||
Epoint Epoint_list
|
||||
{}
|
||||
| Epoint
|
||||
{}
|
||||
;
|
||||
|
||||
Epoint:
|
||||
'(' ConstOp ConstOp DirOp ')'
|
||||
{
|
||||
int dir;
|
||||
|
||||
if (sp->num_exits % REALLOC == 0) {
|
||||
if (sp->exit == NULL)
|
||||
sp->exit = (EXIT *) malloc((sp->num_exits +
|
||||
REALLOC) * sizeof (EXIT));
|
||||
else
|
||||
sp->exit = (EXIT *) realloc(sp->exit,
|
||||
(sp->num_exits + REALLOC) *
|
||||
sizeof (EXIT));
|
||||
if (sp->exit == NULL)
|
||||
return (yyerror("No memory available."));
|
||||
}
|
||||
dir = dir_no($4);
|
||||
sp->exit[sp->num_exits].x = $2;
|
||||
sp->exit[sp->num_exits].y = $3;
|
||||
sp->exit[sp->num_exits].dir = dir;
|
||||
check_edge($2, $3);
|
||||
check_edir($2, $3, dir);
|
||||
sp->num_exits++;
|
||||
}
|
||||
;
|
||||
|
||||
Apoint_list:
|
||||
Apoint Apoint_list
|
||||
{}
|
||||
| Apoint
|
||||
{}
|
||||
;
|
||||
|
||||
Apoint:
|
||||
'(' ConstOp ConstOp DirOp ')'
|
||||
{
|
||||
int dir;
|
||||
|
||||
if (sp->num_airports % REALLOC == 0) {
|
||||
if (sp->airport == NULL)
|
||||
sp->airport=(AIRPORT *)malloc((sp->num_airports
|
||||
+ REALLOC) * sizeof(AIRPORT));
|
||||
else
|
||||
sp->airport = (AIRPORT *) realloc(sp->airport,
|
||||
(sp->num_airports + REALLOC) *
|
||||
sizeof(AIRPORT));
|
||||
if (sp->airport == NULL)
|
||||
return (yyerror("No memory available."));
|
||||
}
|
||||
dir = dir_no($4);
|
||||
sp->airport[sp->num_airports].x = $2;
|
||||
sp->airport[sp->num_airports].y = $3;
|
||||
sp->airport[sp->num_airports].dir = dir;
|
||||
check_point($2, $3);
|
||||
check_adir($2, $3, dir);
|
||||
sp->num_airports++;
|
||||
}
|
||||
;
|
||||
|
||||
Lline_list:
|
||||
Lline Lline_list
|
||||
{}
|
||||
| Lline
|
||||
{}
|
||||
;
|
||||
|
||||
Lline:
|
||||
'[' '(' ConstOp ConstOp ')' '(' ConstOp ConstOp ')' ']'
|
||||
{
|
||||
if (sp->num_lines % REALLOC == 0) {
|
||||
if (sp->line == NULL)
|
||||
sp->line = (LINE *) malloc((sp->num_lines +
|
||||
REALLOC) * sizeof (LINE));
|
||||
else
|
||||
sp->line = (LINE *) realloc(sp->line,
|
||||
(sp->num_lines + REALLOC) *
|
||||
sizeof (LINE));
|
||||
if (sp->line == NULL)
|
||||
return (yyerror("No memory available."));
|
||||
}
|
||||
sp->line[sp->num_lines].p1.x = $3;
|
||||
sp->line[sp->num_lines].p1.y = $4;
|
||||
sp->line[sp->num_lines].p2.x = $7;
|
||||
sp->line[sp->num_lines].p2.y = $8;
|
||||
check_line($3, $4, $7, $8);
|
||||
sp->num_lines++;
|
||||
}
|
||||
;
|
||||
%%
|
||||
|
||||
check_edge(x, y)
|
||||
{
|
||||
if (!(x == 0) && !(x == sp->width - 1) &&
|
||||
!(y == 0) && !(y == sp->height - 1))
|
||||
yyerror("edge value not on edge.");
|
||||
}
|
||||
|
||||
check_point(x, y)
|
||||
{
|
||||
if (x < 1 || x >= sp->width - 1)
|
||||
yyerror("X value out of range.");
|
||||
if (y < 1 || y >= sp->height - 1)
|
||||
yyerror("Y value out of range.");
|
||||
}
|
||||
|
||||
check_linepoint(x, y)
|
||||
{
|
||||
if (x < 0 || x >= sp->width)
|
||||
yyerror("X value out of range.");
|
||||
if (y < 0 || y >= sp->height)
|
||||
yyerror("Y value out of range.");
|
||||
}
|
||||
|
||||
check_line(x1, y1, x2, y2)
|
||||
{
|
||||
int d1, d2;
|
||||
|
||||
check_linepoint(x1, y1);
|
||||
check_linepoint(x2, y2);
|
||||
|
||||
d1 = ABS(x2 - x1);
|
||||
d2 = ABS(y2 - y1);
|
||||
|
||||
if (!(d1 == d2) && !(d1 == 0) && !(d2 == 0))
|
||||
yyerror("Bad line endpoints.");
|
||||
}
|
||||
|
||||
yyerror(s)
|
||||
{
|
||||
fprintf(stderr, "\"%s\": line %d: %s\n", file, line, s);
|
||||
errors++;
|
||||
|
||||
return (errors);
|
||||
}
|
||||
|
||||
check_edir(x, y, dir)
|
||||
{
|
||||
int bad = 0;
|
||||
|
||||
if (x == sp->width - 1)
|
||||
x = 2;
|
||||
else if (x != 0)
|
||||
x = 1;
|
||||
if (y == sp->height - 1)
|
||||
y = 2;
|
||||
else if (y != 0)
|
||||
y = 1;
|
||||
|
||||
switch (x * 10 + y) {
|
||||
case 00: if (dir != 3) bad++; break;
|
||||
case 01: if (dir < 1 || dir > 3) bad++; break;
|
||||
case 02: if (dir != 1) bad++; break;
|
||||
case 10: if (dir < 3 || dir > 5) bad++; break;
|
||||
case 11: break;
|
||||
case 12: if (dir > 1 && dir < 7) bad++; break;
|
||||
case 20: if (dir != 5) bad++; break;
|
||||
case 21: if (dir < 5) bad++; break;
|
||||
case 22: if (dir != 7) bad++; break;
|
||||
default:
|
||||
yyerror("Unknown value in checkdir! Get help!");
|
||||
break;
|
||||
}
|
||||
if (bad)
|
||||
yyerror("Bad direction for entrance at exit.");
|
||||
}
|
||||
|
||||
check_adir(x, y, dir)
|
||||
{
|
||||
}
|
||||
|
||||
checkdefs()
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
if (sp->width == 0) {
|
||||
yyerror("'width' undefined.");
|
||||
err++;
|
||||
}
|
||||
if (sp->height == 0) {
|
||||
yyerror("'height' undefined.");
|
||||
err++;
|
||||
}
|
||||
if (sp->update_secs == 0) {
|
||||
yyerror("'update' undefined.");
|
||||
err++;
|
||||
}
|
||||
if (sp->newplane_time == 0) {
|
||||
yyerror("'newplane' undefined.");
|
||||
err++;
|
||||
}
|
||||
if (err)
|
||||
return (-1);
|
||||
else
|
||||
return (0);
|
||||
}
|
418
games/atc/graphics.c
Normal file
418
games/atc/graphics.c
Normal file
@ -0,0 +1,418 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.h"
|
||||
#ifdef SYSV
|
||||
#include <errno.h>
|
||||
#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)
|
||||
C_SCREEN *scp;
|
||||
{
|
||||
register int i, j;
|
||||
char str[3], *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?<?";
|
||||
for (i = 0; i < scp->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;
|
||||
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)
|
||||
char *str;
|
||||
{
|
||||
wmove(input, 0, pos);
|
||||
waddstr(input, str);
|
||||
wrefresh(input);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
ioclrtobot()
|
||||
{
|
||||
wclrtobot(input);
|
||||
wrefresh(input);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
ioerror(pos, len, str)
|
||||
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)
|
||||
PLANE *p;
|
||||
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 */
|
||||
}
|
86
games/atc/include.h
Normal file
86
games/atc/include.h
Normal file
@ -0,0 +1,86 @@
|
||||
/*-
|
||||
* 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.
|
||||
*
|
||||
* @(#)include.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#ifdef BSD
|
||||
#include <sgtty.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#ifdef SYSV
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <curses.h>
|
||||
|
||||
#ifdef SYSV
|
||||
#define index strchr
|
||||
#define rindex strrchr
|
||||
#define bcopy(a,b,c) memcpy((b), (a), (c))
|
||||
#define bzero(a,b) memset((a), '\0', (b))
|
||||
#define srandom srand
|
||||
#define random rand
|
||||
#define sgttyb termio
|
||||
#define sg_erase c_cc[2]
|
||||
#define sg_kill c_cc[3]
|
||||
#endif
|
||||
|
||||
#include "def.h"
|
||||
#include "struct.h"
|
||||
#include "extern.h"
|
||||
#include "tunable.h"
|
663
games/atc/input.c
Normal file
663
games/atc/input.c
Normal file
@ -0,0 +1,663 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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[] = "@(#)input.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif not lint
|
||||
|
||||
#include "include.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
#define MAXRULES 6
|
||||
#define MAXDEPTH 15
|
||||
|
||||
#define RETTOKEN '\n'
|
||||
#ifdef SYSV
|
||||
#define CRTOKEN '\r'
|
||||
#endif
|
||||
#define REDRAWTOKEN '\014' /* CTRL(L) */
|
||||
#define SHELLTOKEN '!'
|
||||
#define HELPTOKEN '?'
|
||||
#define ALPHATOKEN 256
|
||||
#define NUMTOKEN 257
|
||||
|
||||
typedef struct {
|
||||
int token;
|
||||
int to_state;
|
||||
char *str;
|
||||
char *(*func)();
|
||||
} RULE;
|
||||
|
||||
typedef struct {
|
||||
int num_rules;
|
||||
RULE *rule;
|
||||
} STATE;
|
||||
|
||||
typedef struct {
|
||||
char str[20];
|
||||
int state;
|
||||
int rule;
|
||||
int ch;
|
||||
int pos;
|
||||
} STACK;
|
||||
|
||||
#define T_RULE stack[level].rule
|
||||
#define T_STATE stack[level].state
|
||||
#define T_STR stack[level].str
|
||||
#define T_POS stack[level].pos
|
||||
#define T_CH stack[level].ch
|
||||
|
||||
#define NUMELS(a) (sizeof (a) / sizeof (*(a)))
|
||||
|
||||
#define NUMSTATES NUMELS(st)
|
||||
|
||||
char *setplane(), *circle(), *left(), *right(), *Left(), *Right(),
|
||||
*beacon(), *ex_it(), *climb(), *descend(), *setalt(), *setrelalt(),
|
||||
*benum(), *to_dir(), *rel_dir(), *delayb(), *mark(), *unmark(),
|
||||
*airport(), *turn(), *ignore();
|
||||
|
||||
RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane},
|
||||
{ RETTOKEN, -1, "", NULL },
|
||||
#ifdef SYSV
|
||||
{ CRTOKEN, -1, "", NULL },
|
||||
#endif
|
||||
{ HELPTOKEN, 12, " [a-z]<ret>", NULL }},
|
||||
state1[] = { { 't', 2, " turn", turn },
|
||||
{ 'a', 3, " altitude:", NULL },
|
||||
{ 'c', 4, " circle", circle },
|
||||
{ 'm', 7, " mark", mark },
|
||||
{ 'u', 7, " unmark", unmark },
|
||||
{ 'i', 7, " ignore", ignore },
|
||||
{ HELPTOKEN, 12, " tacmui", NULL }},
|
||||
state2[] = { { 'l', 6, " left", left },
|
||||
{ 'r', 6, " right", right },
|
||||
{ 'L', 4, " left 90", Left },
|
||||
{ 'R', 4, " right 90", Right },
|
||||
{ 't', 11, " towards", NULL },
|
||||
{ 'w', 4, " to 0", to_dir },
|
||||
{ 'e', 4, " to 45", to_dir },
|
||||
{ 'd', 4, " to 90", to_dir },
|
||||
{ 'c', 4, " to 135", to_dir },
|
||||
{ 'x', 4, " to 180", to_dir },
|
||||
{ 'z', 4, " to 225", to_dir },
|
||||
{ 'a', 4, " to 270", to_dir },
|
||||
{ 'q', 4, " to 315", to_dir },
|
||||
{ HELPTOKEN, 12, " lrLRt<dir>", NULL }},
|
||||
state3[] = { { '+', 10, " climb", climb },
|
||||
{ 'c', 10, " climb", climb },
|
||||
{ '-', 10, " descend", descend },
|
||||
{ 'd', 10, " descend", descend },
|
||||
{ NUMTOKEN, 7, " %c000 feet", setalt },
|
||||
{ HELPTOKEN, 12, " +-cd[0-9]", NULL }},
|
||||
state4[] = { { '@', 9, " at", NULL },
|
||||
{ 'a', 9, " at", NULL },
|
||||
{ RETTOKEN, -1, "", NULL },
|
||||
#ifdef SYSV
|
||||
{ CRTOKEN, -1, "", NULL },
|
||||
#endif
|
||||
{ HELPTOKEN, 12, " @a<ret>", NULL }},
|
||||
state5[] = { { NUMTOKEN, 7, "%c", delayb },
|
||||
{ HELPTOKEN, 12, " [0-9]", NULL }},
|
||||
state6[] = { { '@', 9, " at", NULL },
|
||||
{ 'a', 9, " at", NULL },
|
||||
{ 'w', 4, " 0", rel_dir },
|
||||
{ 'e', 4, " 45", rel_dir },
|
||||
{ 'd', 4, " 90", rel_dir },
|
||||
{ 'c', 4, " 135", rel_dir },
|
||||
{ 'x', 4, " 180", rel_dir },
|
||||
{ 'z', 4, " 225", rel_dir },
|
||||
{ 'a', 4, " 270", rel_dir },
|
||||
{ 'q', 4, " 315", rel_dir },
|
||||
{ RETTOKEN, -1, "", NULL },
|
||||
#ifdef SYSV
|
||||
{ CRTOKEN, -1, "", NULL },
|
||||
#endif
|
||||
{ HELPTOKEN, 12, " @a<dir><ret>",NULL }},
|
||||
state7[] = { { RETTOKEN, -1, "", NULL },
|
||||
#ifdef SYSV
|
||||
{ CRTOKEN, -1, "", NULL },
|
||||
#endif
|
||||
{ HELPTOKEN, 12, " <ret>", NULL }},
|
||||
state8[] = { { NUMTOKEN, 4, "%c", benum },
|
||||
{ HELPTOKEN, 12, " [0-9]", NULL }},
|
||||
state9[] = { { 'b', 5, " beacon #", NULL },
|
||||
{ '*', 5, " beacon #", NULL },
|
||||
{ HELPTOKEN, 12, " b*", NULL }},
|
||||
state10[] = { { NUMTOKEN, 7, " %c000 ft", setrelalt},
|
||||
{ HELPTOKEN, 12, " [0-9]", NULL }},
|
||||
state11[] = { { 'b', 8, " beacon #", beacon },
|
||||
{ '*', 8, " beacon #", beacon },
|
||||
{ 'e', 8, " exit #", ex_it },
|
||||
{ 'a', 8, " airport #", airport },
|
||||
{ HELPTOKEN, 12, " b*ea", NULL }},
|
||||
state12[] = { { -1, -1, "", NULL }};
|
||||
|
||||
#define DEF_STATE(s) { NUMELS(s), (s) }
|
||||
|
||||
STATE st[] = {
|
||||
DEF_STATE(state0), DEF_STATE(state1), DEF_STATE(state2),
|
||||
DEF_STATE(state3), DEF_STATE(state4), DEF_STATE(state5),
|
||||
DEF_STATE(state6), DEF_STATE(state7), DEF_STATE(state8),
|
||||
DEF_STATE(state9), DEF_STATE(state10), DEF_STATE(state11),
|
||||
DEF_STATE(state12)
|
||||
};
|
||||
|
||||
PLANE p;
|
||||
STACK stack[MAXDEPTH];
|
||||
int level;
|
||||
int tval;
|
||||
int dest_type, dest_no, dir;
|
||||
|
||||
pop()
|
||||
{
|
||||
if (level == 0)
|
||||
return (-1);
|
||||
level--;
|
||||
|
||||
ioclrtoeol(T_POS);
|
||||
|
||||
strcpy(T_STR, "");
|
||||
T_RULE = -1;
|
||||
T_CH = -1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
rezero()
|
||||
{
|
||||
iomove(0);
|
||||
|
||||
level = 0;
|
||||
T_STATE = 0;
|
||||
T_RULE = -1;
|
||||
T_CH = -1;
|
||||
T_POS = 0;
|
||||
strcpy(T_STR, "");
|
||||
}
|
||||
|
||||
push(ruleno, ch)
|
||||
{
|
||||
int newstate, newpos;
|
||||
|
||||
(void)sprintf(T_STR, st[T_STATE].rule[ruleno].str, tval);
|
||||
T_RULE = ruleno;
|
||||
T_CH = ch;
|
||||
newstate = st[T_STATE].rule[ruleno].to_state;
|
||||
newpos = T_POS + strlen(T_STR);
|
||||
|
||||
ioaddstr(T_POS, T_STR);
|
||||
|
||||
if (level == 0)
|
||||
ioclrtobot();
|
||||
level++;
|
||||
T_STATE = newstate;
|
||||
T_POS = newpos;
|
||||
T_RULE = -1;
|
||||
strcpy(T_STR, "");
|
||||
}
|
||||
|
||||
getcommand()
|
||||
{
|
||||
int c, i, done;
|
||||
char *s, *(*func)();
|
||||
PLANE *pp;
|
||||
|
||||
rezero();
|
||||
|
||||
do {
|
||||
c = gettoken();
|
||||
if (c == tty_new.sg_erase) {
|
||||
if (pop() < 0)
|
||||
noise();
|
||||
} else if (c == tty_new.sg_kill) {
|
||||
while (pop() >= 0)
|
||||
;
|
||||
} else {
|
||||
done = 0;
|
||||
for (i = 0; i < st[T_STATE].num_rules; i++) {
|
||||
if (st[T_STATE].rule[i].token == c ||
|
||||
st[T_STATE].rule[i].token == tval) {
|
||||
push(i, (c >= ALPHATOKEN) ? tval : c);
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!done)
|
||||
noise();
|
||||
}
|
||||
} while (T_STATE != -1);
|
||||
|
||||
if (level == 1)
|
||||
return (1); /* forced update */
|
||||
|
||||
dest_type = T_NODEST;
|
||||
|
||||
for (i = 0; i < level; i++) {
|
||||
func = st[stack[i].state].rule[stack[i].rule].func;
|
||||
if (func != NULL)
|
||||
if ((s = (*func)(stack[i].ch)) != NULL) {
|
||||
ioerror(stack[i].pos, strlen(stack[i].str), s);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
pp = findplane(p.plane_no);
|
||||
if (pp->new_altitude != p.new_altitude)
|
||||
pp->new_altitude = p.new_altitude;
|
||||
else if (pp->status != p.status)
|
||||
pp->status = p.status;
|
||||
else {
|
||||
pp->new_dir = p.new_dir;
|
||||
pp->delayd = p.delayd;
|
||||
pp->delayd_no = p.delayd_no;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
noise()
|
||||
{
|
||||
putchar('\07');
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
gettoken()
|
||||
{
|
||||
while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN)
|
||||
{
|
||||
if (tval == SHELLTOKEN)
|
||||
{
|
||||
#ifdef BSD
|
||||
struct itimerval itv;
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
int aval;
|
||||
aval = alarm(0);
|
||||
#endif
|
||||
if (fork() == 0) /* child */
|
||||
{
|
||||
char *shell, *base, *getenv(), *strrchr();
|
||||
|
||||
setuid(getuid()); /* turn off setuid bit */
|
||||
done_screen();
|
||||
|
||||
/* run user's favorite shell */
|
||||
if ((shell = getenv("SHELL")) != NULL)
|
||||
{
|
||||
base = strrchr(shell, '/');
|
||||
if (base == NULL)
|
||||
base = shell;
|
||||
else
|
||||
base++;
|
||||
execl(shell, base, 0);
|
||||
}
|
||||
else
|
||||
execl(_PATH_BSHELL, "sh", 0);
|
||||
|
||||
exit(0); /* oops */
|
||||
}
|
||||
|
||||
wait(0);
|
||||
#ifdef BSD
|
||||
ioctl(fileno(stdin), TIOCSETP, &tty_new);
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 1;
|
||||
itv.it_interval.tv_sec = sp->update_secs;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
ioctl(fileno(stdin), TCSETAW, &tty_new);
|
||||
alarm(aval);
|
||||
#endif
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
|
||||
if (isdigit(tval))
|
||||
return (NUMTOKEN);
|
||||
else if (isalpha(tval))
|
||||
return (ALPHATOKEN);
|
||||
else
|
||||
return (tval);
|
||||
}
|
||||
|
||||
char *
|
||||
setplane(c)
|
||||
{
|
||||
PLANE *pp;
|
||||
|
||||
pp = findplane(number(c));
|
||||
if (pp == NULL)
|
||||
return ("Unknown Plane");
|
||||
bcopy(pp, &p, sizeof (p));
|
||||
p.delayd = 0;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
turn(c)
|
||||
{
|
||||
if (p.altitude == 0)
|
||||
return ("Planes at airports may not change direction");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
circle(c)
|
||||
{
|
||||
if (p.altitude == 0)
|
||||
return ("Planes cannot circle on the ground");
|
||||
p.new_dir = MAXDIR;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
left(c)
|
||||
{
|
||||
dir = D_LEFT;
|
||||
p.new_dir = p.dir - 1;
|
||||
if (p.new_dir < 0)
|
||||
p.new_dir += MAXDIR;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
right(c)
|
||||
{
|
||||
dir = D_RIGHT;
|
||||
p.new_dir = p.dir + 1;
|
||||
if (p.new_dir > MAXDIR)
|
||||
p.new_dir -= MAXDIR;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
Left(c)
|
||||
{
|
||||
p.new_dir = p.dir - 2;
|
||||
if (p.new_dir < 0)
|
||||
p.new_dir += MAXDIR;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
Right(c)
|
||||
{
|
||||
p.new_dir = p.dir + 2;
|
||||
if (p.new_dir > MAXDIR)
|
||||
p.new_dir -= MAXDIR;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
delayb(c)
|
||||
{
|
||||
int xdiff, ydiff;
|
||||
|
||||
c -= '0';
|
||||
|
||||
if (c >= sp->num_beacons)
|
||||
return ("Unknown beacon");
|
||||
xdiff = sp->beacon[c].x - p.xpos;
|
||||
xdiff = SGN(xdiff);
|
||||
ydiff = sp->beacon[c].y - p.ypos;
|
||||
ydiff = SGN(ydiff);
|
||||
if (xdiff != displacement[p.dir].dx || ydiff != displacement[p.dir].dy)
|
||||
return ("Beacon is not in flight path");
|
||||
p.delayd = 1;
|
||||
p.delayd_no = c;
|
||||
|
||||
if (dest_type != T_NODEST) {
|
||||
switch (dest_type) {
|
||||
case T_BEACON:
|
||||
xdiff = sp->beacon[dest_no].x - sp->beacon[c].x;
|
||||
ydiff = sp->beacon[dest_no].y - sp->beacon[c].y;
|
||||
break;
|
||||
case T_EXIT:
|
||||
xdiff = sp->exit[dest_no].x - sp->beacon[c].x;
|
||||
ydiff = sp->exit[dest_no].y - sp->beacon[c].y;
|
||||
break;
|
||||
case T_AIRPORT:
|
||||
xdiff = sp->airport[dest_no].x - sp->beacon[c].x;
|
||||
ydiff = sp->airport[dest_no].y - sp->beacon[c].y;
|
||||
break;
|
||||
default:
|
||||
return ("Bad case in delayb! Get help!");
|
||||
break;
|
||||
}
|
||||
if (xdiff == 0 && ydiff == 0)
|
||||
return ("Would already be there");
|
||||
p.new_dir = DIR_FROM_DXDY(xdiff, ydiff);
|
||||
if (p.new_dir == p.dir)
|
||||
return ("Already going in that direction");
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
beacon(c)
|
||||
{
|
||||
dest_type = T_BEACON;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
ex_it(c)
|
||||
{
|
||||
dest_type = T_EXIT;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
airport(c)
|
||||
{
|
||||
dest_type = T_AIRPORT;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
climb(c)
|
||||
{
|
||||
dir = D_UP;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
descend(c)
|
||||
{
|
||||
dir = D_DOWN;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
setalt(c)
|
||||
{
|
||||
if ((p.altitude == c - '0') && (p.new_altitude == p.altitude))
|
||||
return ("Already at that altitude");
|
||||
p.new_altitude = c - '0';
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
setrelalt(c)
|
||||
{
|
||||
if (c == 0)
|
||||
return ("altitude not changed");
|
||||
|
||||
switch (dir) {
|
||||
case D_UP:
|
||||
p.new_altitude = p.altitude + c - '0';
|
||||
break;
|
||||
case D_DOWN:
|
||||
p.new_altitude = p.altitude - (c - '0');
|
||||
break;
|
||||
default:
|
||||
return ("Unknown case in setrelalt! Get help!");
|
||||
break;
|
||||
}
|
||||
if (p.new_altitude < 0)
|
||||
return ("Altitude would be too low");
|
||||
else if (p.new_altitude > 9)
|
||||
return ("Altitude would be too high");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
benum(c)
|
||||
{
|
||||
dest_no = c -= '0';
|
||||
|
||||
switch (dest_type) {
|
||||
case T_BEACON:
|
||||
if (c >= sp->num_beacons)
|
||||
return ("Unknown beacon");
|
||||
p.new_dir = DIR_FROM_DXDY(sp->beacon[c].x - p.xpos,
|
||||
sp->beacon[c].y - p.ypos);
|
||||
break;
|
||||
case T_EXIT:
|
||||
if (c >= sp->num_exits)
|
||||
return ("Unknown exit");
|
||||
p.new_dir = DIR_FROM_DXDY(sp->exit[c].x - p.xpos,
|
||||
sp->exit[c].y - p.ypos);
|
||||
break;
|
||||
case T_AIRPORT:
|
||||
if (c >= sp->num_airports)
|
||||
return ("Unknown airport");
|
||||
p.new_dir = DIR_FROM_DXDY(sp->airport[c].x - p.xpos,
|
||||
sp->airport[c].y - p.ypos);
|
||||
break;
|
||||
default:
|
||||
return ("Unknown case in benum! Get help!");
|
||||
break;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
to_dir(c)
|
||||
{
|
||||
p.new_dir = dir_no(c);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
rel_dir(c)
|
||||
{
|
||||
int angle;
|
||||
|
||||
angle = dir_no(c);
|
||||
switch (dir) {
|
||||
case D_LEFT:
|
||||
p.new_dir = p.dir - angle;
|
||||
if (p.new_dir < 0)
|
||||
p.new_dir += MAXDIR;
|
||||
break;
|
||||
case D_RIGHT:
|
||||
p.new_dir = p.dir + angle;
|
||||
if (p.new_dir >= MAXDIR)
|
||||
p.new_dir -= MAXDIR;
|
||||
break;
|
||||
default:
|
||||
return ("Bizarre direction in rel_dir! Get help!");
|
||||
break;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
mark(c)
|
||||
{
|
||||
if (p.altitude == 0)
|
||||
return ("Cannot mark planes on the ground");
|
||||
if (p.status == S_MARKED)
|
||||
return ("Already marked");
|
||||
p.status = S_MARKED;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
unmark(c)
|
||||
{
|
||||
if (p.altitude == 0)
|
||||
return ("Cannot unmark planes on the ground");
|
||||
if (p.status == S_UNMARKED)
|
||||
return ("Already unmarked");
|
||||
p.status = S_UNMARKED;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
ignore(c)
|
||||
{
|
||||
if (p.altitude == 0)
|
||||
return ("Cannot ignore planes on the ground");
|
||||
if (p.status == S_IGNORED)
|
||||
return ("Already ignored");
|
||||
p.status = S_IGNORED;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
dir_no(ch)
|
||||
char ch;
|
||||
{
|
||||
int dir;
|
||||
|
||||
switch (ch) {
|
||||
case 'w': dir = 0; break;
|
||||
case 'e': dir = 1; break;
|
||||
case 'd': dir = 2; break;
|
||||
case 'c': dir = 3; break;
|
||||
case 'x': dir = 4; break;
|
||||
case 'z': dir = 5; break;
|
||||
case 'a': dir = 6; break;
|
||||
case 'q': dir = 7; break;
|
||||
default:
|
||||
fprintf(stderr, "bad character in dir_no\n");
|
||||
break;
|
||||
}
|
||||
return (dir);
|
||||
}
|
69
games/atc/lex.l
Normal file
69
games/atc/lex.l
Normal file
@ -0,0 +1,69 @@
|
||||
%{
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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[] = "@(#)lex.l 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "y.tab.h"
|
||||
extern int line;
|
||||
|
||||
%}
|
||||
%%
|
||||
[0-9]+ { yylval.ival = atoi(yytext); return(ConstOp); }
|
||||
height { return(HeightOp); }
|
||||
width { return(WidthOp); }
|
||||
newplane { return(NewplaneOp); }
|
||||
update { return(UpdateOp); }
|
||||
airport { return(AirportOp); }
|
||||
line { return(LineOp); }
|
||||
exit { return(ExitOp); }
|
||||
beacon { return(BeaconOp); }
|
||||
[wedcxzaq] { yylval.cval = *yytext; return (DirOp); }
|
||||
[ \t]+ { }
|
||||
#[^\n]*\n { line++; }
|
||||
\n { line++; }
|
||||
. { return *yytext; }
|
115
games/atc/list.c
Normal file
115
games/atc/list.c
Normal file
@ -0,0 +1,115 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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[] = "@(#)list.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "include.h"
|
||||
|
||||
PLANE *
|
||||
newplane()
|
||||
{
|
||||
return ((PLANE *) calloc(1, sizeof (PLANE)));
|
||||
}
|
||||
|
||||
append(l, p)
|
||||
LIST *l;
|
||||
PLANE *p;
|
||||
{
|
||||
PLANE *q = NULL, *r = NULL;
|
||||
|
||||
if (l->head == NULL) {
|
||||
p->next = p->prev = NULL;
|
||||
l->head = l->tail = p;
|
||||
} else {
|
||||
q = l -> head;
|
||||
|
||||
while (q != NULL && q->plane_no < p->plane_no) {
|
||||
r = q;
|
||||
q = q -> next;
|
||||
}
|
||||
|
||||
if (q) {
|
||||
if (r) {
|
||||
p->prev = r;
|
||||
r->next = p;
|
||||
p->next = q;
|
||||
q->prev = p;
|
||||
} else {
|
||||
p->next = q;
|
||||
p->prev = NULL;
|
||||
q->prev = p;
|
||||
l->head = p;
|
||||
}
|
||||
} else {
|
||||
l->tail->next = p;
|
||||
p->next = NULL;
|
||||
p->prev = l->tail;
|
||||
l->tail = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete(l, p)
|
||||
LIST *l;
|
||||
PLANE *p;
|
||||
{
|
||||
if (l->head == NULL)
|
||||
loser(p, "deleted a non-existant plane! Get help!");
|
||||
|
||||
if (l->head == p && l->tail == p)
|
||||
l->head = l->tail = NULL;
|
||||
else if (l->head == p) {
|
||||
l->head = p->next;
|
||||
l->head->prev = NULL;
|
||||
} else if (l->tail == p) {
|
||||
l->tail = p->prev;
|
||||
l->tail->next = NULL;
|
||||
} else {
|
||||
p->prev->next = p->next;
|
||||
p->next->prev = p->prev;
|
||||
}
|
||||
}
|
247
games/atc/log.c
Normal file
247
games/atc/log.c
Normal file
@ -0,0 +1,247 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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[] = "@(#)log.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif not lint
|
||||
|
||||
#include "include.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
compar(a, b)
|
||||
SCORE *a, *b;
|
||||
{
|
||||
if (b->planes == a->planes)
|
||||
return (b->time - a->time);
|
||||
else
|
||||
return (b->planes - a->planes);
|
||||
}
|
||||
|
||||
#define SECAMIN 60
|
||||
#define MINAHOUR 60
|
||||
#define HOURADAY 24
|
||||
#define SECAHOUR (SECAMIN * MINAHOUR)
|
||||
#define SECADAY (SECAHOUR * HOURADAY)
|
||||
#define DAY(t) ((t) / SECADAY)
|
||||
#define HOUR(t) (((t) % SECADAY) / SECAHOUR)
|
||||
#define MIN(t) (((t) % SECAHOUR) / SECAMIN)
|
||||
#define SEC(t) ((t) % SECAMIN)
|
||||
|
||||
char *
|
||||
timestr(t)
|
||||
{
|
||||
static char s[80];
|
||||
|
||||
if (DAY(t) > 0)
|
||||
(void)sprintf(s, "%dd+%02dhrs", DAY(t), HOUR(t));
|
||||
else if (HOUR(t) > 0)
|
||||
(void)sprintf(s, "%d:%02d:%02d", HOUR(t), MIN(t), SEC(t));
|
||||
else if (MIN(t) > 0)
|
||||
(void)sprintf(s, "%d:%02d", MIN(t), SEC(t));
|
||||
else if (SEC(t) > 0)
|
||||
(void)sprintf(s, ":%02d", SEC(t));
|
||||
else
|
||||
*s = '\0';
|
||||
|
||||
return (s);
|
||||
}
|
||||
|
||||
log_score(list_em)
|
||||
{
|
||||
register int i, fd, num_scores = 0, good, changed = 0, found = 0;
|
||||
struct passwd *pw;
|
||||
FILE *fp;
|
||||
char *cp, *index(), *rindex();
|
||||
SCORE score[100], thisscore;
|
||||
#ifdef SYSV
|
||||
struct utsname name;
|
||||
#endif
|
||||
|
||||
umask(0);
|
||||
fd = open(_PATH_SCORE, O_CREAT|O_RDWR, 0644);
|
||||
if (fd < 0) {
|
||||
perror(_PATH_SCORE);
|
||||
return (-1);
|
||||
}
|
||||
/*
|
||||
* This is done to take advantage of stdio, while still
|
||||
* allowing a O_CREAT during the open(2) of the log file.
|
||||
*/
|
||||
fp = fdopen(fd, "r+");
|
||||
if (fp == NULL) {
|
||||
perror(_PATH_SCORE);
|
||||
return (-1);
|
||||
}
|
||||
#ifdef BSD
|
||||
if (flock(fileno(fp), LOCK_EX) < 0)
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
while (lockf(fileno(fp), F_LOCK, 1) < 0)
|
||||
#endif
|
||||
{
|
||||
perror("flock");
|
||||
return (-1);
|
||||
}
|
||||
for (;;) {
|
||||
good = fscanf(fp, "%s %s %s %d %d %d",
|
||||
score[num_scores].name,
|
||||
score[num_scores].host,
|
||||
score[num_scores].game,
|
||||
&score[num_scores].planes,
|
||||
&score[num_scores].time,
|
||||
&score[num_scores].real_time);
|
||||
if (good != 6 || ++num_scores >= NUM_SCORES)
|
||||
break;
|
||||
}
|
||||
if (!test_mode && !list_em) {
|
||||
if ((pw = (struct passwd *) getpwuid(getuid())) == NULL) {
|
||||
fprintf(stderr,
|
||||
"getpwuid failed for uid %d. Who are you?\n",
|
||||
getuid());
|
||||
return (-1);
|
||||
}
|
||||
strcpy(thisscore.name, pw->pw_name);
|
||||
#ifdef BSD
|
||||
if (gethostname(thisscore.host, sizeof (thisscore.host)) < 0) {
|
||||
perror("gethostname");
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
uname(&name);
|
||||
strcpy(thisscore.host, name.sysname);
|
||||
#endif
|
||||
|
||||
cp = rindex(file, '/');
|
||||
if (cp == NULL) {
|
||||
fprintf(stderr, "log: where's the '/' in %s?\n", file);
|
||||
return (-1);
|
||||
}
|
||||
cp++;
|
||||
strcpy(thisscore.game, cp);
|
||||
|
||||
thisscore.time = clck;
|
||||
thisscore.planes = safe_planes;
|
||||
thisscore.real_time = time(0) - start_time;
|
||||
|
||||
for (i = 0; i < num_scores; i++) {
|
||||
if (strcmp(thisscore.name, score[i].name) == 0 &&
|
||||
strcmp(thisscore.host, score[i].host) == 0 &&
|
||||
strcmp(thisscore.game, score[i].game) == 0) {
|
||||
if (thisscore.time > score[i].time) {
|
||||
score[i].time = thisscore.time;
|
||||
score[i].planes = thisscore.planes;
|
||||
score[i].real_time =
|
||||
thisscore.real_time;
|
||||
changed++;
|
||||
}
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
for (i = 0; i < num_scores; i++) {
|
||||
if (thisscore.time > score[i].time) {
|
||||
if (num_scores < NUM_SCORES)
|
||||
num_scores++;
|
||||
bcopy(&score[i],
|
||||
&score[num_scores - 1],
|
||||
sizeof (score[i]));
|
||||
bcopy(&thisscore, &score[i],
|
||||
sizeof (score[i]));
|
||||
changed++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found && !changed && num_scores < NUM_SCORES) {
|
||||
bcopy(&thisscore, &score[num_scores],
|
||||
sizeof (score[num_scores]));
|
||||
num_scores++;
|
||||
changed++;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
if (found)
|
||||
puts("You beat your previous score!");
|
||||
else
|
||||
puts("You made the top players list!");
|
||||
qsort(score, num_scores, sizeof (*score), compar);
|
||||
rewind(fp);
|
||||
for (i = 0; i < num_scores; i++)
|
||||
fprintf(fp, "%s %s %s %d %d %d\n",
|
||||
score[i].name, score[i].host,
|
||||
score[i].game, score[i].planes,
|
||||
score[i].time, score[i].real_time);
|
||||
} else {
|
||||
if (found)
|
||||
puts("You didn't beat your previous score.");
|
||||
else
|
||||
puts("You didn't make the top players list.");
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
#ifdef BSD
|
||||
flock(fileno(fp), LOCK_UN);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
/* lock will evaporate upon close */
|
||||
#endif
|
||||
fclose(fp);
|
||||
printf("%2s: %-8s %-8s %-18s %4s %9s %4s\n", "#", "name", "host",
|
||||
"game", "time", "real time", "planes safe");
|
||||
puts("-------------------------------------------------------------------------------");
|
||||
for (i = 0; i < num_scores; i++) {
|
||||
cp = index(score[i].host, '.');
|
||||
if (cp != NULL)
|
||||
*cp = '\0';
|
||||
printf("%2d: %-8s %-8s %-18s %4d %9s %4d\n", i + 1,
|
||||
score[i].name, score[i].host, score[i].game,
|
||||
score[i].time, timestr(score[i].real_time),
|
||||
score[i].planes);
|
||||
}
|
||||
putchar('\n');
|
||||
return (0);
|
||||
}
|
326
games/atc/main.c
Normal file
326
games/atc/main.c
Normal file
@ -0,0 +1,326 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 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[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "include.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
main(ac, av)
|
||||
char *av[];
|
||||
{
|
||||
int seed;
|
||||
int f_usage = 0, f_list = 0, f_showscore = 0;
|
||||
int f_printpath = 0;
|
||||
char *file = NULL;
|
||||
char *name, *ptr;
|
||||
#ifdef BSD
|
||||
struct itimerval itv;
|
||||
#endif
|
||||
extern char *default_game(), *okay_game();
|
||||
extern void log_score(), quit(), update();
|
||||
|
||||
start_time = seed = time(0);
|
||||
|
||||
name = *av++;
|
||||
while (*av) {
|
||||
#ifndef SAVEDASH
|
||||
if (**av == '-')
|
||||
*++*av;
|
||||
else
|
||||
break;
|
||||
#endif
|
||||
ptr = *av++;
|
||||
while (*ptr) {
|
||||
switch (*ptr) {
|
||||
case '?':
|
||||
case 'u':
|
||||
f_usage++;
|
||||
break;
|
||||
case 'l':
|
||||
f_list++;
|
||||
break;
|
||||
case 's':
|
||||
case 't':
|
||||
f_showscore++;
|
||||
break;
|
||||
case 'p':
|
||||
f_printpath++;
|
||||
break;
|
||||
case 'r':
|
||||
seed = atoi(*av);
|
||||
av++;
|
||||
break;
|
||||
case 'f':
|
||||
case 'g':
|
||||
file = *av;
|
||||
av++;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown option '%c'\n", *ptr,
|
||||
name);
|
||||
f_usage++;
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
srandom(seed);
|
||||
|
||||
if (f_usage)
|
||||
fprintf(stderr,
|
||||
"Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
|
||||
name);
|
||||
if (f_showscore)
|
||||
log_score(1);
|
||||
if (f_list)
|
||||
list_games();
|
||||
if (f_printpath) {
|
||||
char buf[100];
|
||||
|
||||
strcpy(buf, _PATH_GAMES);
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
puts(buf);
|
||||
}
|
||||
|
||||
if (f_usage || f_showscore || f_list || f_printpath)
|
||||
exit(0);
|
||||
|
||||
if (file == NULL)
|
||||
file = default_game();
|
||||
else
|
||||
file = okay_game(file);
|
||||
|
||||
if (file == NULL || read_file(file) < 0)
|
||||
exit(1);
|
||||
|
||||
init_gr();
|
||||
setup_screen(sp);
|
||||
|
||||
addplane();
|
||||
|
||||
signal(SIGINT, quit);
|
||||
signal(SIGQUIT, quit);
|
||||
#ifdef BSD
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGSTOP, SIG_IGN);
|
||||
#endif
|
||||
signal(SIGHUP, log_score);
|
||||
signal(SIGTERM, log_score);
|
||||
|
||||
#ifdef BSD
|
||||
ioctl(fileno(stdin), TIOCGETP, &tty_start);
|
||||
bcopy(&tty_start, &tty_new, sizeof(tty_new));
|
||||
tty_new.sg_flags |= CBREAK;
|
||||
tty_new.sg_flags &= ~ECHO;
|
||||
ioctl(fileno(stdin), TIOCSETP, &tty_new);
|
||||
#endif
|
||||
|
||||
#ifdef SYSV
|
||||
ioctl(fileno(stdin), TCGETA, &tty_start);
|
||||
bcopy(&tty_start, &tty_new, sizeof(tty_new));
|
||||
tty_new.c_lflag &= ~ICANON;
|
||||
tty_new.c_lflag &= ~ECHO;
|
||||
tty_new.c_cc[VMIN] = 1;
|
||||
tty_new.c_cc[VTIME] = 0;
|
||||
ioctl(fileno(stdin), TCSETAW, &tty_new);
|
||||
#endif
|
||||
|
||||
signal(SIGALRM, update);
|
||||
|
||||
#ifdef BSD
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 1;
|
||||
itv.it_interval.tv_sec = sp->update_secs;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(sp->update_secs);
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
if (getcommand() != 1)
|
||||
planewin();
|
||||
else {
|
||||
#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
|
||||
|
||||
update();
|
||||
|
||||
#ifdef BSD
|
||||
itv.it_value.tv_sec = sp->update_secs;
|
||||
itv.it_value.tv_usec = 0;
|
||||
itv.it_interval.tv_sec = sp->update_secs;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(sp->update_secs);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
read_file(s)
|
||||
char *s;
|
||||
{
|
||||
extern FILE *yyin;
|
||||
int retval;
|
||||
|
||||
file = s;
|
||||
yyin = fopen(s, "r");
|
||||
if (yyin == NULL) {
|
||||
perror(s);
|
||||
return (-1);
|
||||
}
|
||||
retval = yyparse();
|
||||
fclose(yyin);
|
||||
|
||||
if (retval != 0)
|
||||
return (-1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *
|
||||
default_game()
|
||||
{
|
||||
FILE *fp;
|
||||
static char file[256];
|
||||
char line[256], games[256];
|
||||
|
||||
strcpy(games, _PATH_GAMES);
|
||||
strcat(games, GAMES);
|
||||
|
||||
if ((fp = fopen(games, "r")) == NULL) {
|
||||
perror(games);
|
||||
return (NULL);
|
||||
}
|
||||
if (fgets(line, sizeof(line), fp) == NULL) {
|
||||
fprintf(stderr, "%s: no default game available\n", games);
|
||||
return (NULL);
|
||||
}
|
||||
fclose(fp);
|
||||
line[strlen(line) - 1] = '\0';
|
||||
strcpy(file, _PATH_GAMES);
|
||||
strcat(file, line);
|
||||
return (file);
|
||||
}
|
||||
|
||||
char *
|
||||
okay_game(s)
|
||||
char *s;
|
||||
{
|
||||
FILE *fp;
|
||||
static char file[256];
|
||||
char *ret = NULL, line[256], games[256];
|
||||
|
||||
strcpy(games, _PATH_GAMES);
|
||||
strcat(games, GAMES);
|
||||
|
||||
if ((fp = fopen(games, "r")) == NULL) {
|
||||
perror(games);
|
||||
return (NULL);
|
||||
}
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
line[strlen(line) - 1] = '\0';
|
||||
if (strcmp(s, line) == 0) {
|
||||
strcpy(file, _PATH_GAMES);
|
||||
strcat(file, line);
|
||||
ret = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
if (ret == NULL) {
|
||||
test_mode = 1;
|
||||
ret = s;
|
||||
fprintf(stderr, "%s: %s: game not found\n", games, s);
|
||||
fprintf(stderr, "Your score will not be logged.\n");
|
||||
sleep(2); /* give the guy time to read it */
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
list_games()
|
||||
{
|
||||
FILE *fp;
|
||||
char line[256], games[256];
|
||||
int num_games = 0;
|
||||
|
||||
strcpy(games, _PATH_GAMES);
|
||||
strcat(games, GAMES);
|
||||
|
||||
if ((fp = fopen(games, "r")) == NULL) {
|
||||
perror(games);
|
||||
return (-1);
|
||||
}
|
||||
puts("available games:");
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
printf(" %s", line);
|
||||
num_games++;
|
||||
}
|
||||
fclose(fp);
|
||||
if (num_games == 0) {
|
||||
fprintf(stderr, "%s: no games available\n", games);
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
39
games/atc/pathnames.h
Normal file
39
games/atc/pathnames.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 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.
|
||||
*
|
||||
* @(#)pathnames.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
#include <paths.h>
|
||||
|
||||
#define _PATH_GAMES "/usr/share/games/atc/"
|
||||
#define _PATH_SCORE "/var/games/atc_score"
|
111
games/atc/struct.h
Normal file
111
games/atc/struct.h
Normal file
@ -0,0 +1,111 @@
|
||||
/*-
|
||||
* 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.
|
||||
*
|
||||
* @(#)struct.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int x, y;
|
||||
int dir; /* used only sometimes */
|
||||
} SCREEN_POS;
|
||||
|
||||
typedef struct {
|
||||
SCREEN_POS p1, p2;
|
||||
} LINE;
|
||||
|
||||
typedef SCREEN_POS EXIT;
|
||||
typedef SCREEN_POS BEACON;
|
||||
typedef SCREEN_POS AIRPORT;
|
||||
|
||||
typedef struct {
|
||||
int width, height;
|
||||
int update_secs;
|
||||
int newplane_time;
|
||||
int num_exits;
|
||||
int num_lines;
|
||||
int num_beacons;
|
||||
int num_airports;
|
||||
EXIT *exit;
|
||||
LINE *line;
|
||||
BEACON *beacon;
|
||||
AIRPORT *airport;
|
||||
} C_SCREEN;
|
||||
|
||||
typedef struct plane {
|
||||
struct plane *next, *prev;
|
||||
int status;
|
||||
int plane_no;
|
||||
int plane_type;
|
||||
int orig_no;
|
||||
int orig_type;
|
||||
int dest_no;
|
||||
int dest_type;
|
||||
int altitude;
|
||||
int new_altitude;
|
||||
int dir;
|
||||
int new_dir;
|
||||
int fuel;
|
||||
int xpos;
|
||||
int ypos;
|
||||
int delayd;
|
||||
int delayd_no;
|
||||
} PLANE;
|
||||
|
||||
typedef struct {
|
||||
PLANE *head, *tail;
|
||||
} LIST;
|
||||
|
||||
typedef struct {
|
||||
char name[10];
|
||||
char host[256];
|
||||
char game[256];
|
||||
int planes;
|
||||
int time;
|
||||
int real_time;
|
||||
} SCORE;
|
||||
|
||||
typedef struct displacement {
|
||||
int dx;
|
||||
int dy;
|
||||
} DISPLACEMENT;
|
56
games/atc/tunable.c
Normal file
56
games/atc/tunable.c
Normal file
@ -0,0 +1,56 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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[] = "@(#)tunable.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* NUM_SCORES - Number of scores that are kept track of.
|
||||
* Keep this greater than 0, but less than 100.
|
||||
* 4 lines are printed above the score, one below + your prompt, so
|
||||
* to prevent scrolling: 6 + NUM_SCORES <= 24 (lines on an average terminal).
|
||||
*/
|
||||
int NUM_SCORES = 18;
|
48
games/atc/tunable.h
Normal file
48
games/atc/tunable.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*-
|
||||
* 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.
|
||||
*
|
||||
* @(#)tunable.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
extern int NUM_SCORES;
|
410
games/atc/update.c
Normal file
410
games/atc/update.c
Normal file
@ -0,0 +1,410 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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[] = "@(#)update.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif not lint
|
||||
|
||||
#include "include.h"
|
||||
|
||||
update()
|
||||
{
|
||||
int i, dir_diff, mask, unclean;
|
||||
PLANE *pp, *p1, *p2, *p;
|
||||
|
||||
#ifdef BSD
|
||||
mask = sigblock(sigmask(SIGINT));
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(0);
|
||||
signal(SIGALRM, update);
|
||||
#endif
|
||||
|
||||
clck++;
|
||||
|
||||
erase_all();
|
||||
|
||||
/* put some planes in the air */
|
||||
do {
|
||||
unclean = 0;
|
||||
for (pp = ground.head; pp != NULL; pp = pp->next) {
|
||||
if (pp->new_altitude > 0) {
|
||||
delete(&ground, pp);
|
||||
append(&air, pp);
|
||||
unclean = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (unclean);
|
||||
|
||||
/* do altitude change and basic movement */
|
||||
for (pp = air.head; pp != NULL; pp = pp->next) {
|
||||
/* type 0 only move every other turn */
|
||||
if (pp->plane_type == 0 && clck & 1)
|
||||
continue;
|
||||
|
||||
pp->fuel--;
|
||||
if (pp->fuel < 0)
|
||||
loser(pp, "ran out of fuel.");
|
||||
|
||||
pp->altitude += SGN(pp->new_altitude - pp->altitude);
|
||||
|
||||
if (!pp->delayd) {
|
||||
dir_diff = pp->new_dir - pp->dir;
|
||||
/*
|
||||
* Allow for circle commands
|
||||
*/
|
||||
if (pp->new_dir >= 0 && pp->new_dir < MAXDIR) {
|
||||
if (dir_diff > MAXDIR/2)
|
||||
dir_diff -= MAXDIR;
|
||||
else if (dir_diff < -(MAXDIR/2))
|
||||
dir_diff += MAXDIR;
|
||||
}
|
||||
if (dir_diff > 2)
|
||||
dir_diff = 2;
|
||||
else if (dir_diff < -2)
|
||||
dir_diff = -2;
|
||||
pp->dir += dir_diff;
|
||||
if (pp->dir >= MAXDIR)
|
||||
pp->dir -= MAXDIR;
|
||||
else if (pp->dir < 0)
|
||||
pp->dir += MAXDIR;
|
||||
}
|
||||
pp->xpos += displacement[pp->dir].dx;
|
||||
pp->ypos += displacement[pp->dir].dy;
|
||||
|
||||
if (pp->delayd && pp->xpos == sp->beacon[pp->delayd_no].x &&
|
||||
pp->ypos == sp->beacon[pp->delayd_no].y) {
|
||||
pp->delayd = 0;
|
||||
if (pp->status == S_UNMARKED)
|
||||
pp->status = S_MARKED;
|
||||
}
|
||||
|
||||
switch (pp->dest_type) {
|
||||
case T_AIRPORT:
|
||||
if (pp->xpos == sp->airport[pp->dest_no].x &&
|
||||
pp->ypos == sp->airport[pp->dest_no].y &&
|
||||
pp->altitude == 0) {
|
||||
if (pp->dir != sp->airport[pp->dest_no].dir)
|
||||
loser(pp, "landed in the wrong direction.");
|
||||
else {
|
||||
pp->status = S_GONE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case T_EXIT:
|
||||
if (pp->xpos == sp->exit[pp->dest_no].x &&
|
||||
pp->ypos == sp->exit[pp->dest_no].y) {
|
||||
if (pp->altitude != 9)
|
||||
loser(pp, "exited at the wrong altitude.");
|
||||
else {
|
||||
pp->status = S_GONE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
loser(pp, "has a bizarre destination, get help!");
|
||||
}
|
||||
if (pp->altitude > 9)
|
||||
/* "this is impossible" */
|
||||
loser(pp, "exceded flight ceiling.");
|
||||
if (pp->altitude <= 0) {
|
||||
for (i = 0; i < sp->num_airports; i++)
|
||||
if (pp->xpos == sp->airport[i].x &&
|
||||
pp->ypos == sp->airport[i].y) {
|
||||
if (pp->dest_type == T_AIRPORT)
|
||||
loser(pp,
|
||||
"landed at the wrong airport.");
|
||||
else
|
||||
loser(pp,
|
||||
"landed instead of exited.");
|
||||
}
|
||||
loser(pp, "crashed on the ground.");
|
||||
}
|
||||
if (pp->xpos < 1 || pp->xpos >= sp->width - 1 ||
|
||||
pp->ypos < 1 || pp->ypos >= sp->height - 1) {
|
||||
for (i = 0; i < sp->num_exits; i++)
|
||||
if (pp->xpos == sp->exit[i].x &&
|
||||
pp->ypos == sp->exit[i].y) {
|
||||
if (pp->dest_type == T_EXIT)
|
||||
loser(pp,
|
||||
"exited via the wrong exit.");
|
||||
else
|
||||
loser(pp,
|
||||
"exited instead of landed.");
|
||||
}
|
||||
loser(pp, "illegally left the flight arena.");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Traverse the list once, deleting the planes that are gone.
|
||||
*/
|
||||
for (pp = air.head; pp != NULL; pp = p2) {
|
||||
p2 = pp->next;
|
||||
if (pp->status == S_GONE) {
|
||||
safe_planes++;
|
||||
delete(&air, pp);
|
||||
}
|
||||
}
|
||||
|
||||
draw_all();
|
||||
|
||||
for (p1 = air.head; p1 != NULL; p1 = p1->next)
|
||||
for (p2 = p1->next; p2 != NULL; p2 = p2->next)
|
||||
if (too_close(p1, p2, 1)) {
|
||||
static char buf[80];
|
||||
|
||||
(void)sprintf(buf, "collided with plane '%c'.",
|
||||
name(p2));
|
||||
loser(p1, buf);
|
||||
}
|
||||
/*
|
||||
* Check every other update. Actually, only add on even updates.
|
||||
* Otherwise, prop jobs show up *on* entrance. Remember that
|
||||
* we don't update props on odd updates.
|
||||
*/
|
||||
if ((rand() % sp->newplane_time) == 0)
|
||||
addplane();
|
||||
|
||||
#ifdef BSD
|
||||
sigsetmask(mask);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(sp->update_secs);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *
|
||||
command(pp)
|
||||
PLANE *pp;
|
||||
{
|
||||
static char buf[50], *bp, *comm_start;
|
||||
char *index();
|
||||
|
||||
buf[0] = '\0';
|
||||
bp = buf;
|
||||
(void)sprintf(bp, "%c%d%c%c%d: ", name(pp), pp->altitude,
|
||||
(pp->fuel < LOWFUEL) ? '*' : ' ',
|
||||
(pp->dest_type == T_AIRPORT) ? 'A' : 'E', pp->dest_no);
|
||||
|
||||
comm_start = bp = index(buf, '\0');
|
||||
if (pp->altitude == 0)
|
||||
(void)sprintf(bp, "Holding @ A%d", pp->orig_no);
|
||||
else if (pp->new_dir >= MAXDIR || pp->new_dir < 0)
|
||||
strcpy(bp, "Circle");
|
||||
else if (pp->new_dir != pp->dir)
|
||||
(void)sprintf(bp, "%d", dir_deg(pp->new_dir));
|
||||
|
||||
bp = index(buf, '\0');
|
||||
if (pp->delayd)
|
||||
(void)sprintf(bp, " @ B%d", pp->delayd_no);
|
||||
|
||||
bp = index(buf, '\0');
|
||||
if (*comm_start == '\0' &&
|
||||
(pp->status == S_UNMARKED || pp->status == S_IGNORED))
|
||||
strcpy(bp, "---------");
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* char */
|
||||
name(p)
|
||||
PLANE *p;
|
||||
{
|
||||
if (p->plane_type == 0)
|
||||
return ('A' + p->plane_no);
|
||||
else
|
||||
return ('a' + p->plane_no);
|
||||
}
|
||||
|
||||
number(l)
|
||||
{
|
||||
if (l < 'a' && l > 'z' && l < 'A' && l > 'Z')
|
||||
return (-1);
|
||||
else if (l >= 'a' && l <= 'z')
|
||||
return (l - 'a');
|
||||
else
|
||||
return (l - 'A');
|
||||
}
|
||||
|
||||
next_plane()
|
||||
{
|
||||
static int last_plane = -1;
|
||||
PLANE *pp;
|
||||
int found, start_plane = last_plane;
|
||||
|
||||
do {
|
||||
found = 0;
|
||||
last_plane++;
|
||||
if (last_plane >= 26)
|
||||
last_plane = 0;
|
||||
for (pp = air.head; pp != NULL; pp = pp->next)
|
||||
if (pp->plane_no == last_plane) {
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
for (pp = ground.head; pp != NULL; pp = pp->next)
|
||||
if (pp->plane_no == last_plane) {
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
} while (found && last_plane != start_plane);
|
||||
if (last_plane == start_plane)
|
||||
return (-1);
|
||||
return (last_plane);
|
||||
}
|
||||
|
||||
addplane()
|
||||
{
|
||||
PLANE p, *pp, *p1;
|
||||
int i, num_starts, close, rnd, rnd2, pnum;
|
||||
|
||||
bzero(&p, sizeof (p));
|
||||
|
||||
p.status = S_MARKED;
|
||||
p.plane_type = random() % 2;
|
||||
|
||||
num_starts = sp->num_exits + sp->num_airports;
|
||||
rnd = random() % num_starts;
|
||||
|
||||
if (rnd < sp->num_exits) {
|
||||
p.dest_type = T_EXIT;
|
||||
p.dest_no = rnd;
|
||||
} else {
|
||||
p.dest_type = T_AIRPORT;
|
||||
p.dest_no = rnd - sp->num_exits;
|
||||
}
|
||||
|
||||
/* loop until we get a plane not near another */
|
||||
for (i = 0; i < num_starts; i++) {
|
||||
/* loop till we get a different start point */
|
||||
while ((rnd2 = random() % num_starts) == rnd)
|
||||
;
|
||||
if (rnd2 < sp->num_exits) {
|
||||
p.orig_type = T_EXIT;
|
||||
p.orig_no = rnd2;
|
||||
p.xpos = sp->exit[rnd2].x;
|
||||
p.ypos = sp->exit[rnd2].y;
|
||||
p.new_dir = p.dir = sp->exit[rnd2].dir;
|
||||
p.altitude = p.new_altitude = 7;
|
||||
close = 0;
|
||||
for (p1 = air.head; p1 != NULL; p1 = p1->next)
|
||||
if (too_close(p1, &p, 4)) {
|
||||
close++;
|
||||
break;
|
||||
}
|
||||
if (close)
|
||||
continue;
|
||||
} else {
|
||||
p.orig_type = T_AIRPORT;
|
||||
p.orig_no = rnd2 - sp->num_exits;
|
||||
p.xpos = sp->airport[p.orig_no].x;
|
||||
p.ypos = sp->airport[p.orig_no].y;
|
||||
p.new_dir = p.dir = sp->airport[p.orig_no].dir;
|
||||
p.altitude = p.new_altitude = 0;
|
||||
}
|
||||
p.fuel = sp->width + sp->height;
|
||||
break;
|
||||
}
|
||||
if (i >= num_starts)
|
||||
return (-1);
|
||||
pnum = next_plane();
|
||||
if (pnum < 0)
|
||||
return (-1);
|
||||
p.plane_no = pnum;
|
||||
|
||||
pp = newplane();
|
||||
bcopy(&p, pp, sizeof (p));
|
||||
|
||||
if (pp->orig_type == T_AIRPORT)
|
||||
append(&ground, pp);
|
||||
else
|
||||
append(&air, pp);
|
||||
|
||||
return (pp->dest_type);
|
||||
}
|
||||
|
||||
PLANE *
|
||||
findplane(n)
|
||||
{
|
||||
PLANE *pp;
|
||||
|
||||
for (pp = air.head; pp != NULL; pp = pp->next)
|
||||
if (pp->plane_no == n)
|
||||
return (pp);
|
||||
for (pp = ground.head; pp != NULL; pp = pp->next)
|
||||
if (pp->plane_no == n)
|
||||
return (pp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
too_close(p1, p2, dist)
|
||||
PLANE *p1, *p2;
|
||||
{
|
||||
if (ABS(p1->altitude - p2->altitude) <= dist &&
|
||||
ABS(p1->xpos - p2->xpos) <= dist && ABS(p1->ypos - p2->ypos) <= dist)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
dir_deg(d)
|
||||
{
|
||||
switch (d) {
|
||||
case 0: return (0);
|
||||
case 1: return (45);
|
||||
case 2: return (90);
|
||||
case 3: return (135);
|
||||
case 4: return (180);
|
||||
case 5: return (225);
|
||||
case 6: return (270);
|
||||
case 7: return (315);
|
||||
default:
|
||||
return (-1);
|
||||
}
|
||||
}
|
5
games/backgammon/Makefile
Normal file
5
games/backgammon/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
SUBDIR= backgammon teachgammon
|
||||
|
||||
.include <bsd.subdir.mk>
|
14
games/backgammon/backgammon/Makefile
Normal file
14
games/backgammon/backgammon/Makefile
Normal file
@ -0,0 +1,14 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
PROG= backgammon
|
||||
CFLAGS+=-DV7 -I${.CURDIR}/../common_source
|
||||
SRCS= allow.c board.c check.c extra.c fancy.c init.c main.c move.c \
|
||||
odds.c one.c save.c subs.c table.c text.c version.c
|
||||
MAN6= backgammon.6
|
||||
DPADD= ${LIBTERM} ${LIBCOMPAT}
|
||||
LDADD= -ltermcap -lcompat
|
||||
.PATH: ${.CURDIR}/../common_source
|
||||
HIDEGAME=hidegame
|
||||
|
||||
.include "../../Makefile.inc"
|
||||
.include <bsd.prog.mk>
|
205
games/backgammon/backgammon/backgammon.6
Normal file
205
games/backgammon/backgammon/backgammon.6
Normal file
@ -0,0 +1,205 @@
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)backgammon.6 8.1 (Berkeley) 5/31/93
|
||||
.\"
|
||||
.TH BACKGAMMON 6 "May 31, 1993"
|
||||
.UC 5
|
||||
.SH NAME
|
||||
backgammon \- the game of backgammon
|
||||
.SH SYNOPSIS
|
||||
.B backgammon
|
||||
[ - ] [ n r w b pr pw pb t\c
|
||||
.I term
|
||||
s\c
|
||||
.I file
|
||||
]
|
||||
.SH DESCRIPTION
|
||||
This program lets you play backgammon against the computer
|
||||
or against a "friend".
|
||||
All commands only are one letter,
|
||||
so you don't need to type a carriage return,
|
||||
except at the end of a move.
|
||||
The program is mostly self documenting,
|
||||
so that a question mark (?) will usually get some help.
|
||||
If you answer `y' when the program asks if you want the rules,
|
||||
you will get text explaining the rules of the game,
|
||||
some hints on strategy,
|
||||
instruction on how to use the program,
|
||||
and a tutorial consisting of a practice game against the computer.
|
||||
A description of how to use the program can be
|
||||
obtained by answering `y' when it asks if you want instructions.
|
||||
.PP
|
||||
The possible arguments for backgammon
|
||||
(most are unnecessary but some are very convenient)
|
||||
consist of:
|
||||
.ne 11
|
||||
.PP
|
||||
.na
|
||||
.TP 8
|
||||
.B n
|
||||
don't ask for rules or instructions
|
||||
.TP 8
|
||||
.B r
|
||||
player is red (implies n)
|
||||
.TP 8
|
||||
.B w
|
||||
player is white (implies n)
|
||||
.TP 8
|
||||
.B b
|
||||
two players, red and white (implies n)
|
||||
.TP 8
|
||||
.B pr
|
||||
print the board before red's turn
|
||||
.TP 8
|
||||
.B pw
|
||||
print the board before white's turn
|
||||
.TP 8
|
||||
.B pb
|
||||
print the board before both player's turn
|
||||
.TP 8
|
||||
.B t\fIterm
|
||||
terminal is type
|
||||
.IR term ,
|
||||
uses /etc/termcap
|
||||
.TP 8
|
||||
.B s\fIfile
|
||||
recover previously saved game from
|
||||
.IR file .
|
||||
(This can also be done by executing the saved file,
|
||||
i.e., typing its name in as a command)
|
||||
.ad
|
||||
.PP
|
||||
Arguments may be optionally preceded by a `-'.
|
||||
Several arguments may be concatenated together,
|
||||
but not after `s' or `t' arguments,
|
||||
since they can be followed by an arbitrary string.
|
||||
Any unrecognized arguments are ignored.
|
||||
An argument of a lone `-' gets a description of possible arguments.
|
||||
.PP
|
||||
If
|
||||
.IR term
|
||||
has capabilities for direct cursor movement (see
|
||||
.IR termcap (5))
|
||||
.IR backgammon
|
||||
``fixes'' the board after each move,
|
||||
so the board does not need to be reprinted,
|
||||
unless the screen suffers some horrendous malady.
|
||||
Also, any `p' option will be ignored.
|
||||
(The `t' option is not necessary unless the terminal type does not match
|
||||
the entry in the /etc/termcap data base.)
|
||||
.SH QUICK\ REFERENCE
|
||||
When the program prompts by typing only your color,
|
||||
type a space or carriage return to roll, or
|
||||
.ne 5
|
||||
.PP
|
||||
.na
|
||||
.TP 8
|
||||
.B d
|
||||
to double
|
||||
.TP 8
|
||||
.B p
|
||||
to print the board
|
||||
.TP 8
|
||||
.B q
|
||||
to quit
|
||||
.TP 8
|
||||
.B s
|
||||
to save the game for later
|
||||
.PP
|
||||
.i0
|
||||
.ad
|
||||
When the program prompts with 'Move:', type
|
||||
.ne 4
|
||||
.PP
|
||||
.na
|
||||
.TP 8
|
||||
.B p
|
||||
to print the board
|
||||
.TP 8
|
||||
.B q
|
||||
to quit
|
||||
.TP 8
|
||||
.B s
|
||||
to save the game
|
||||
.ad
|
||||
.i0
|
||||
.PP
|
||||
or a
|
||||
.IR move ,
|
||||
which is a sequence of
|
||||
.ne 4
|
||||
.PP
|
||||
.na
|
||||
.TP 8
|
||||
.B s-f
|
||||
move from
|
||||
.BR s
|
||||
to
|
||||
.BR f
|
||||
.TP 8
|
||||
.B s/r
|
||||
move one man on
|
||||
.BR s
|
||||
the roll
|
||||
.BR r
|
||||
.ad
|
||||
.PP
|
||||
separated by commas or spaces and ending with a newline.
|
||||
Available abbreviations are
|
||||
.ne 4
|
||||
.PP
|
||||
.na
|
||||
.TP 10
|
||||
.B s-f1-f2
|
||||
means
|
||||
.BR s-f1,f1-f2
|
||||
.TP 10
|
||||
.B s/r1r2
|
||||
means
|
||||
.BR s/r1,s/r2
|
||||
.ad
|
||||
.PP
|
||||
Use `b' for bar and `h' for home,
|
||||
or 0 or 25 as appropriate.
|
||||
.SH AUTHOR
|
||||
Alan Char
|
||||
.SH FILES
|
||||
.TP 25
|
||||
/usr/games/teachgammon
|
||||
\- rules and tutorial
|
||||
.br
|
||||
.TP 25
|
||||
/etc/termcap
|
||||
\- terminal capabilities
|
||||
.SH BUGS
|
||||
.PP
|
||||
The program's strategy needs much work.
|
253
games/backgammon/backgammon/extra.c
Normal file
253
games/backgammon/backgammon/extra.c
Normal file
@ -0,0 +1,253 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)extra.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <stdio.h>
|
||||
FILE *trace;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* dble()
|
||||
* Have the current player double and ask opponent to accept.
|
||||
*/
|
||||
|
||||
dble () {
|
||||
register 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 */
|
||||
|
||||
#ifdef DEBUG
|
||||
register 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;
|
||||
|
||||
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 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;
|
||||
|
||||
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);
|
||||
}
|
591
games/backgammon/backgammon/main.c
Normal file
591
games/backgammon/backgammon/main.c
Normal file
@ -0,0 +1,591 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 <stdio.h>
|
||||
#include "back.h"
|
||||
|
||||
#define MVPAUSE 5 /* time to sleep when stuck */
|
||||
#define MAXUSERS 35 /* maximum number of users */
|
||||
|
||||
char *instr[]; /* text of instructions */
|
||||
char *message[]; /* update message */
|
||||
char ospeed; /* tty output speed */
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
char *contin[] = { /* pause message */
|
||||
"(Type a newline to continue.)",
|
||||
"",
|
||||
0
|
||||
};
|
||||
|
||||
static char user1a[] =
|
||||
"Sorry, you cannot play backgammon when there are more than ";
|
||||
static char user1b[] =
|
||||
" users\non the system.";
|
||||
static char user2a[] =
|
||||
"\nThere are now more than ";
|
||||
static char user2b[] =
|
||||
" users on the system, so you cannot play\nanother game. ";
|
||||
static char rules[] = "\nDo you want the rules of the game?";
|
||||
static char noteach[] = "Teachgammon not available!\n\007";
|
||||
static char need[] = "Do you need instructions for this program?";
|
||||
static char askcol[] =
|
||||
"Enter 'r' to play red, 'w' to play white, 'b' to play both:";
|
||||
static char rollr[] = "Red rolls a ";
|
||||
static char rollw[] = ". White rolls a ";
|
||||
static char rstart[] = ". Red starts.\n";
|
||||
static char wstart[] = ". White starts.\n";
|
||||
static char toobad1[] = "Too bad, ";
|
||||
static char unable[] = " is unable to use that roll.\n";
|
||||
static char toobad2[] = ". Too bad, ";
|
||||
static char cantmv[] = " can't move.\n";
|
||||
static char bgammon[] = "Backgammon! ";
|
||||
static char gammon[] = "Gammon! ";
|
||||
static char again[] = ".\nWould you like to play again?";
|
||||
static char svpromt[] = "Would you like to save this game?";
|
||||
|
||||
static 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 */
|
||||
long t; /* time for random num generator */
|
||||
|
||||
/* initialization */
|
||||
bflag = 2; /* default no board */
|
||||
signal (2,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 */
|
||||
|
||||
/* check user count */
|
||||
# ifdef CORY
|
||||
if (ucount() > MAXUSERS) {
|
||||
writel (user1a);
|
||||
wrint (MAXUSERS);
|
||||
writel (user1b);
|
||||
getout();
|
||||
}
|
||||
# endif
|
||||
|
||||
/* get terminal
|
||||
* capabilities, and
|
||||
* decide if it can
|
||||
* cursor address */
|
||||
tflag = getcaps (getenv ("TERM"));
|
||||
/* use whole screen
|
||||
* for text */
|
||||
if (tflag)
|
||||
begscr = 0;
|
||||
t = time(0);
|
||||
srandom(t); /* 'random' seed */
|
||||
|
||||
#ifdef V7
|
||||
while (*++argv != 0) /* process arguments */
|
||||
#else
|
||||
while (*++argv != -1) /* process arguments */
|
||||
#endif
|
||||
getarg (&argv);
|
||||
args[acnt] = '\0';
|
||||
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 */
|
||||
execl (TEACH,"teachgammon",args,0);
|
||||
|
||||
tflag = 0; /* error! */
|
||||
writel (noteach);
|
||||
exit();
|
||||
} else { /* if not rules, then
|
||||
* instructions */
|
||||
writel (need);
|
||||
if (yorn(0)) { /* print instructions */
|
||||
clear();
|
||||
text (instr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 (14,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();
|
||||
|
||||
/* check user count */
|
||||
# ifdef CORY
|
||||
if (ucount() > MAXUSERS) {
|
||||
writel (user2a);
|
||||
wrint (MAXUSERS);
|
||||
writel (user2b);
|
||||
rfl = 1;
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
|
||||
/* 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 ();
|
||||
}
|
551
games/backgammon/backgammon/move.c
Normal file
551
games/backgammon/backgammon/move.c
Normal file
@ -0,0 +1,551 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <stdio.h>
|
||||
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 */
|
||||
|
||||
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 swapped; /* see if swapped also tested */
|
||||
|
||||
{
|
||||
register int pos; /* position on board */
|
||||
register 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 */
|
||||
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 */
|
||||
|
||||
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 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;
|
||||
{
|
||||
register int i;
|
||||
register 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 */
|
||||
|
||||
#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 */
|
||||
{
|
||||
register 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;
|
||||
|
||||
#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;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
132
games/backgammon/backgammon/text.c
Normal file
132
games/backgammon/backgammon/text.c
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)text.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
char *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 <s>-<f>, where <s> is the starting position, and <f> 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 <s>/<r> where <s> is the",
|
||||
"starting position, an <r> 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 <s>/<r> format as by",
|
||||
"entering more than one <r>, 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};
|
||||
|
||||
|
||||
text (t)
|
||||
char **t;
|
||||
|
||||
{
|
||||
register int i;
|
||||
register 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);
|
||||
}
|
41
games/backgammon/backgammon/version.c
Normal file
41
games/backgammon/backgammon/version.c
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 1980, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)version.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
char *message[] = {
|
||||
"Last updated on Saturday, January 11, 1986.",
|
||||
0
|
||||
};
|
109
games/backgammon/common_source/allow.c
Normal file
109
games/backgammon/common_source/allow.c
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 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);
|
||||
}
|
127
games/backgammon/common_source/back.h
Normal file
127
games/backgammon/common_source/back.h
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* @(#)back.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
#include <sgtty.h>
|
||||
|
||||
#define rnum(r) (random()%r)
|
||||
#define D0 dice[0]
|
||||
#define D1 dice[1]
|
||||
#define swap {D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;}
|
||||
|
||||
/*
|
||||
*
|
||||
* Some numerical conventions:
|
||||
*
|
||||
* Arrays have white's value in [0], red in [1].
|
||||
* Numeric values which are one color or the other use
|
||||
* -1 for white, 1 for red.
|
||||
* Hence, white will be negative values, red positive one.
|
||||
* This makes a lot of sense since white is going in decending
|
||||
* order around the board, and red is ascending.
|
||||
*
|
||||
*/
|
||||
|
||||
char EXEC[]; /* object for main program */
|
||||
char TEACH[]; /* object for tutorial program */
|
||||
|
||||
int pnum; /* color of player:
|
||||
-1 = white
|
||||
1 = red
|
||||
0 = both
|
||||
2 = not yet init'ed */
|
||||
char args[100]; /* args passed to teachgammon and back */
|
||||
int acnt; /* length of args */
|
||||
int aflag; /* flag to ask for rules or instructions */
|
||||
int bflag; /* flag for automatic board printing */
|
||||
int cflag; /* case conversion flag */
|
||||
int hflag; /* flag for cleaning screen */
|
||||
int mflag; /* backgammon flag */
|
||||
int raflag; /* 'roll again' flag for recovered game */
|
||||
int rflag; /* recovered game flag */
|
||||
int tflag; /* cursor addressing flag */
|
||||
int rfl; /* saved value of rflag */
|
||||
int iroll; /* special flag for inputting rolls */
|
||||
int board[26]; /* board: negative values are white,
|
||||
positive are red */
|
||||
int dice[2]; /* value of dice */
|
||||
int mvlim; /* 'move limit': max. number of moves */
|
||||
int mvl; /* working copy of mvlim */
|
||||
int p[5]; /* starting position of moves */
|
||||
int g[5]; /* ending position of moves (goals) */
|
||||
int h[4]; /* flag for each move if a man was hit */
|
||||
int cturn; /* whose turn it currently is:
|
||||
-1 = white
|
||||
1 = red
|
||||
0 = just quitted
|
||||
-2 = white just lost
|
||||
2 = red just lost */
|
||||
int d0; /* flag if dice have been reversed from
|
||||
original position */
|
||||
int table[6][6]; /* odds table for possible rolls */
|
||||
int rscore; /* red's score */
|
||||
int wscore; /* white's score */
|
||||
int gvalue; /* value of game (64 max.) */
|
||||
int dlast; /* who doubled last (0 = neither) */
|
||||
int bar; /* position of bar for current player */
|
||||
int home; /* position of home for current player */
|
||||
int off[2]; /* number of men off board */
|
||||
int *offptr; /* pointer to off for current player */
|
||||
int *offopp; /* pointer to off for opponent */
|
||||
int in[2]; /* number of men in inner table */
|
||||
int *inptr; /* pointer to in for current player */
|
||||
int *inopp; /* pointer to in for opponent */
|
||||
|
||||
int ncin; /* number of characters in cin */
|
||||
char cin[100]; /* input line of current move
|
||||
(used for reconstructing input after
|
||||
a backspace) */
|
||||
|
||||
char *color[];
|
||||
/* colors as strings */
|
||||
char **colorptr; /* color of current player */
|
||||
char **Colorptr; /* color of current player, capitalized */
|
||||
int colen; /* length of color of current player */
|
||||
|
||||
struct sgttyb tty; /* tty information buffer */
|
||||
int old; /* original tty status */
|
||||
int noech; /* original tty status without echo */
|
||||
int raw; /* raw tty status, no echo */
|
||||
|
||||
int curr; /* row position of cursor */
|
||||
int curc; /* column position of cursor */
|
||||
int begscr; /* 'beginning' of screen
|
||||
(not including board) */
|
||||
|
||||
int getout(); /* function to exit backgammon cleanly */
|
751
games/backgammon/common_source/backgammon.c
Normal file
751
games/backgammon/common_source/backgammon.c
Normal file
@ -0,0 +1,751 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)backgammon.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
** The game of Backgammon
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define WHITE 0
|
||||
#define BROWN 1
|
||||
#define NIL (-1)
|
||||
#define MAXGMOV 10
|
||||
#define MAXIMOVES 1000
|
||||
#define RULES "/usr/games/lib/backrules"
|
||||
|
||||
char level; /*'b'=beginner, 'i'=intermediate, 'e'=expert*/
|
||||
|
||||
int die1;
|
||||
int die2;
|
||||
int i;
|
||||
int j;
|
||||
int l;
|
||||
int m;
|
||||
int pflg = 1;
|
||||
int nobroll = 0;
|
||||
int count;
|
||||
int imoves;
|
||||
int goodmoves[MAXGMOV];
|
||||
int probmoves[MAXGMOV];
|
||||
|
||||
int brown[] = { /* brown position table */
|
||||
0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
|
||||
0, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
int white[] = { /* white position table */
|
||||
0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
|
||||
0, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
int probability[] = {
|
||||
0, 11, 12, 13, 14, 15, 16,
|
||||
06, 05, 04, 03, 02, 01
|
||||
};
|
||||
|
||||
struct {
|
||||
int pos[4];
|
||||
int mov[4];
|
||||
} moves[MAXIMOVES];
|
||||
|
||||
main()
|
||||
{
|
||||
int go[5], tvec[2];
|
||||
int k, n, pid, ret, rpid, t;
|
||||
char s[100];
|
||||
|
||||
srand(time(0));
|
||||
go[5] = NIL;
|
||||
fprintf(stdout, "Instructions? ");
|
||||
gets(s);
|
||||
if(*s == 'y')
|
||||
instructions();
|
||||
putchar('\n');
|
||||
fprintf(stdout, "Opponent's level: b - beginner,\n");
|
||||
fprintf(stdout, "i - intermediate, e - expert? ");
|
||||
level='e';
|
||||
gets(s);
|
||||
if(*s == 'b')
|
||||
level = 'b';
|
||||
else if(*s == 'i')
|
||||
level = 'i';
|
||||
putchar('\n');
|
||||
fprintf(stdout, "You will play brown.\n\n");
|
||||
fprintf(stdout, "Would you like to roll your own dice? ");
|
||||
gets(s);
|
||||
putchar('\n');
|
||||
if(*s == 'y')
|
||||
nobroll = 1;
|
||||
fprintf(stdout, "Would you like to go first? ");
|
||||
gets(s);
|
||||
putchar('\n');
|
||||
if(*s == 'y')
|
||||
goto nowhmove;
|
||||
whitesmv:
|
||||
roll(WHITE);
|
||||
fprintf(stdout, "white rolls %d, %d\n", die1, die2);
|
||||
fprintf(stdout, "white's move is:");
|
||||
if(nextmove(white, brown) == NIL)
|
||||
goto nowhmove;
|
||||
if(piececount(white, 0, 24) == 0){
|
||||
fprintf(stdout, "White wins");
|
||||
if(piececount(brown, 0, 6) != 0)
|
||||
fprintf(stdout, " with a Backgammon!\n");
|
||||
else if (piececount(brown, 0, 24) == 24)
|
||||
fprintf(stdout, " with a Gammon.\n");
|
||||
else
|
||||
fprintf(stdout, ".\n");
|
||||
exit(0);
|
||||
}
|
||||
nowhmove:
|
||||
if(pflg)
|
||||
prtbrd();
|
||||
roll(BROWN);
|
||||
retry:
|
||||
fprintf(stdout, "\nYour roll is %d %d\n", die1, die2);
|
||||
fprintf(stdout, "Move? ");
|
||||
gets(s);
|
||||
switch(*s) {
|
||||
case '\0': /* empty line */
|
||||
fprintf(stdout, "Brown's move skipped.\n");
|
||||
goto whitesmv;
|
||||
|
||||
case 'b': /* how many beared off? */
|
||||
fprintf(stdout, "Brown: %d\n", piececount(brown, 0, 24) - 15);
|
||||
fprintf(stdout, "White: %d\n", piececount(white, 0, 24) - 15);
|
||||
goto retry;
|
||||
|
||||
case 'p': /* print board */
|
||||
prtbrd();
|
||||
goto retry;
|
||||
|
||||
case 's': /* stop auto printing of board */
|
||||
pflg = 0;
|
||||
goto retry;
|
||||
|
||||
case 'r': /* resume auto printing */
|
||||
pflg = 1;
|
||||
goto retry;
|
||||
|
||||
case 'm': /* print possible moves */
|
||||
pmoves();
|
||||
goto retry;
|
||||
|
||||
case 'q': /* i give up */
|
||||
exit(0);
|
||||
|
||||
case '!': /* escape to Shell */
|
||||
if(s[1] != '\0')
|
||||
system(s+1);
|
||||
else if((pid = fork()) == 0) {
|
||||
execl("/bin/sh", "sh", "-", 0);
|
||||
fprintf(stderr, "back: cannot exec /bin/sh!\n");
|
||||
exit(2);
|
||||
}
|
||||
while((rpid = wait(&ret)) != pid && rpid != -1)
|
||||
;
|
||||
goto retry;
|
||||
|
||||
case '?': /* well, what can i do? */
|
||||
fprintf(stdout, "<newline> skip this move\n");
|
||||
fprintf(stdout, "b number beared off\n");
|
||||
fprintf(stdout, "p print board\n");
|
||||
fprintf(stdout, "q quit\n");
|
||||
fprintf(stdout, "r resume auto print of board\n");
|
||||
fprintf(stdout, "s stop auto print of board\n");
|
||||
fprintf(stdout, "! escape to Shell\n");
|
||||
goto retry;
|
||||
}
|
||||
n = sscanf(s,"%d%d%d%d%d",&go[0],&go[1],&go[2],&go[3],&go[4]);
|
||||
if((die1 != die2 && n > 2) || n > 4){
|
||||
fprintf(stdout, "Too many moves.\n");
|
||||
goto retry;
|
||||
}
|
||||
go[n] = NIL;
|
||||
if(*s=='-'){
|
||||
go[0]= -go[0];
|
||||
t=die1;
|
||||
die1=die2;
|
||||
die2=t;
|
||||
}
|
||||
for(k = 0; k < n; k++){
|
||||
if(0 <= go[k] && go[k] <= 24)
|
||||
continue;
|
||||
else{
|
||||
fprintf(stdout, "Move %d illegal.\n", go[k]);
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
if(play(brown, white, go))
|
||||
goto retry;
|
||||
if(piececount(brown, 0, 24) == 0){
|
||||
fprintf(stdout, "Brown wins");
|
||||
if(piececount(white, 0, 6) != 0)
|
||||
fprintf(stdout, " with a Backgammon.\n");
|
||||
else if(piececount(white, 0, 24) == 24)
|
||||
fprintf(stdout, " with a gammon.\n");
|
||||
else
|
||||
fprintf(stdout, ".\n");
|
||||
exit(0);
|
||||
}
|
||||
goto whitesmv;
|
||||
}
|
||||
|
||||
play(player,playee,pos)
|
||||
int *player,*playee,pos[];
|
||||
{
|
||||
int k, n, die, ipos;
|
||||
|
||||
for(k=0; k < player[0]; k++){ /*blots on player[0] must be moved first*/
|
||||
if(pos[k] == NIL)
|
||||
break;
|
||||
if(pos[k] != 0){
|
||||
fprintf(stdout, "Stone on bar must be moved first.\n");
|
||||
return(NIL);
|
||||
}
|
||||
}
|
||||
for(k = 0; (ipos=pos[k]) != NIL; k++){
|
||||
die = k?die2:die1;
|
||||
n = 25-ipos-die;
|
||||
if(player[ipos] == 0)
|
||||
goto badmove;
|
||||
if(n > 0 && playee[n] >= 2)
|
||||
goto badmove;
|
||||
if(n <= 0){
|
||||
if(piececount(player,0,18) != 0)
|
||||
goto badmove;
|
||||
if((ipos+die) != 25 && piececount(player,19,24-die)!=0)
|
||||
goto badmove;
|
||||
}
|
||||
player[ipos]--;
|
||||
player[ipos+die]++;
|
||||
}
|
||||
for(k = 0; pos[k] != NIL; k++){
|
||||
die = k?die2:die1;
|
||||
n = 25-pos[k]-die;
|
||||
if(n>0 && playee[n]==1){
|
||||
playee[n]=0;
|
||||
playee[0]++;
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
|
||||
badmove:
|
||||
fprintf(stdout, "Move %d illegal.\n", ipos);
|
||||
while(k--){
|
||||
die=k?die2:die1;
|
||||
player[pos[k]]++;
|
||||
player[pos[k]+die]--;
|
||||
}
|
||||
return(NIL);
|
||||
}
|
||||
nextmove(player,playee)
|
||||
int *player,*playee;
|
||||
{
|
||||
int k;
|
||||
|
||||
imoves=0;
|
||||
movegen(player,playee);
|
||||
if(die1!=die2){
|
||||
k=die1;
|
||||
die1=die2;
|
||||
die2=k;
|
||||
movegen(player,playee);
|
||||
}
|
||||
if(imoves==0){
|
||||
fprintf(stdout, "no move possible.\n");
|
||||
return(NIL);
|
||||
}
|
||||
k=strategy(player,playee); /*select kth possible move*/
|
||||
prtmov(k);
|
||||
update(player,playee,k);
|
||||
return(0);
|
||||
}
|
||||
prtmov(k)
|
||||
int k;
|
||||
{
|
||||
int n;
|
||||
|
||||
if(k == NIL)
|
||||
fprintf(stdout, "No move possible\n");
|
||||
else for(n = 0; n < 4; n++){
|
||||
if(moves[k].pos[n] == NIL)
|
||||
break;
|
||||
fprintf(stdout, " %d, %d",25-moves[k].pos[n],moves[k].mov[n]);
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
update(player,playee,k)
|
||||
int *player,*playee,k;
|
||||
{
|
||||
int n,t;
|
||||
|
||||
for(n = 0; n < 4; n++){
|
||||
if(moves[k].pos[n] == NIL)
|
||||
break;
|
||||
player[moves[k].pos[n]]--;
|
||||
player[moves[k].pos[n]+moves[k].mov[n]]++;
|
||||
t=25-moves[k].pos[n]-moves[k].mov[n];
|
||||
if(t>0 && playee[t]==1){
|
||||
playee[0]++;
|
||||
playee[t]--;
|
||||
}
|
||||
}
|
||||
}
|
||||
piececount(player,startrow,endrow)
|
||||
int *player,startrow,endrow;
|
||||
{
|
||||
int sum;
|
||||
|
||||
sum=0;
|
||||
while(startrow <= endrow)
|
||||
sum += player[startrow++];
|
||||
return(sum);
|
||||
}
|
||||
pmoves()
|
||||
{
|
||||
int i1, i2;
|
||||
|
||||
fprintf(stdout, "Possible moves are:\n");
|
||||
for(i1 = 0; i1 < imoves; i1++){
|
||||
fprintf(stdout, "\n%d",i1);
|
||||
for (i2 = 0; i2<4; i2++){
|
||||
if(moves[i1].pos[i2] == NIL)
|
||||
break;
|
||||
fprintf(stdout, "%d, %d",moves[i1].pos[i2],moves[i1].mov[i2]);
|
||||
}
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
|
||||
roll(who)
|
||||
{
|
||||
register n;
|
||||
char s[10];
|
||||
|
||||
if(who == BROWN && nobroll) {
|
||||
fprintf(stdout, "Roll? ");
|
||||
gets(s);
|
||||
n = sscanf(s, "%d%d", &die1, &die2);
|
||||
if(n != 2 || die1 < 1 || die1 > 6 || die2 < 1 || die2 > 6)
|
||||
fprintf(stdout, "Illegal - I'll do it!\n");
|
||||
else
|
||||
return;
|
||||
}
|
||||
die1 = ((rand()>>8) % 6) + 1;
|
||||
die2 = ((rand()>>8) % 6) + 1;
|
||||
}
|
||||
|
||||
movegen(mover,movee)
|
||||
int *mover,*movee;
|
||||
{
|
||||
int k;
|
||||
|
||||
for(i = 0; i <= 24; i++){
|
||||
count = 0;
|
||||
if(mover[i] == 0)
|
||||
continue;
|
||||
if((k=25-i-die1) > 0 && movee[k] >= 2)
|
||||
if(mover[0] > 0)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
if(k <= 0){
|
||||
if(piececount(mover, 0, 18) != 0)
|
||||
break;
|
||||
if((i+die1) != 25 && piececount(mover,19,i-1) != 0)
|
||||
break;
|
||||
}
|
||||
mover[i]--;
|
||||
mover[i+die1]++;
|
||||
count = 1;
|
||||
for(j = 0; j <= 24; j++){
|
||||
if(mover[j]==0)
|
||||
continue;
|
||||
if((k=25-j-die2) > 0 && movee[k] >= 2)
|
||||
if(mover[0] > 0)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
if(k <= 0){
|
||||
if(piececount(mover,0,18) != 0)
|
||||
break;
|
||||
if((j+die2) != 25 && piececount(mover,19,j-1) != 0)
|
||||
break;
|
||||
}
|
||||
mover[j]--;
|
||||
mover[j+die2]++;
|
||||
count = 2;
|
||||
if(die1 != die2){
|
||||
moverecord(mover);
|
||||
if(mover[0] > 0)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
for(l = 0; l <= 24; l++){
|
||||
if(mover[l] == 0)
|
||||
continue;
|
||||
if((k=25-l-die1) > 0 && movee[k] >= 2)
|
||||
if(mover[0] > 0)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
if(k <= 0){
|
||||
if(piececount(mover, 0, 18) != 0)
|
||||
break;
|
||||
if((l+die2) != 25 && piececount(mover,19,l-1) != 0)
|
||||
break;
|
||||
}
|
||||
mover[l]--;
|
||||
mover[l+die1]++;
|
||||
count=3;
|
||||
for(m=0;m<=24;m++){
|
||||
if(mover[m]==0)
|
||||
continue;
|
||||
if((k=25-m-die1) >= 0 && movee[k] >= 2)
|
||||
if(mover[0] > 0)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
if(k <= 0){
|
||||
if(piececount(mover,0,18) != 0)
|
||||
break;
|
||||
if((m+die2) != 25 && piececount(mover,19,m-1) != 0)
|
||||
break;
|
||||
}
|
||||
count=4;
|
||||
moverecord(mover);
|
||||
if(mover[0] > 0)
|
||||
break;
|
||||
}
|
||||
if(count == 3)
|
||||
moverecord(mover);
|
||||
else{
|
||||
mover[l]++;
|
||||
mover[l+die1]--;
|
||||
}
|
||||
if(mover[0] > 0)
|
||||
break;
|
||||
}
|
||||
if(count == 2)
|
||||
moverecord(mover);
|
||||
else{
|
||||
mover[j]++;
|
||||
mover[j+die1]--;
|
||||
}
|
||||
if(mover[0] > 0)
|
||||
break;
|
||||
}
|
||||
if(count == 1)
|
||||
moverecord(mover);
|
||||
else{
|
||||
mover[i]++;
|
||||
mover[i+die1]--;
|
||||
}
|
||||
if(mover[0] > 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
moverecord(mover)
|
||||
int *mover;
|
||||
{
|
||||
int t;
|
||||
|
||||
if(imoves < MAXIMOVES) {
|
||||
for(t = 0; t <= 3; t++)
|
||||
moves[imoves].pos[t] = NIL;
|
||||
switch(count) {
|
||||
case 4:
|
||||
moves[imoves].pos[3]=m;
|
||||
moves[imoves].mov[3]=die1;
|
||||
|
||||
case 3:
|
||||
moves[imoves].pos[2]=l;
|
||||
moves[imoves].mov[2]=die1;
|
||||
|
||||
case 2:
|
||||
moves[imoves].pos[1]=j;
|
||||
moves[imoves].mov[1]=die2;
|
||||
|
||||
case 1:
|
||||
moves[imoves].pos[0]=i;
|
||||
moves[imoves].mov[0]=die1;
|
||||
imoves++;
|
||||
}
|
||||
}
|
||||
switch(count) {
|
||||
case 4:
|
||||
break;
|
||||
|
||||
case 3:
|
||||
mover[l]++;
|
||||
mover[l+die1]--;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mover[j]++;
|
||||
mover[j+die2]--;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mover[i]++;
|
||||
mover[i+die1]--;
|
||||
}
|
||||
}
|
||||
|
||||
strategy(player,playee)
|
||||
int *player,*playee;
|
||||
{
|
||||
int k, n, nn, bestval, moveval, prob;
|
||||
|
||||
n = 0;
|
||||
if(imoves == 0)
|
||||
return(NIL);
|
||||
goodmoves[0] = NIL;
|
||||
bestval = -32000;
|
||||
for(k = 0; k < imoves; k++){
|
||||
if((moveval=eval(player,playee,k,&prob)) < bestval)
|
||||
continue;
|
||||
if(moveval > bestval){
|
||||
bestval = moveval;
|
||||
n = 0;
|
||||
}
|
||||
if(n<MAXGMOV){
|
||||
goodmoves[n]=k;
|
||||
probmoves[n++]=prob;
|
||||
}
|
||||
}
|
||||
if(level=='e' && n>1){
|
||||
nn=n;
|
||||
n=0;
|
||||
prob=32000;
|
||||
for(k = 0; k < nn; k++){
|
||||
if((moveval=probmoves[k]) > prob)
|
||||
continue;
|
||||
if(moveval<prob){
|
||||
prob=moveval;
|
||||
n=0;
|
||||
}
|
||||
goodmoves[n]=goodmoves[k];
|
||||
probmoves[n++]=probmoves[k];
|
||||
}
|
||||
}
|
||||
return(goodmoves[(rand()>>4)%n]);
|
||||
}
|
||||
|
||||
eval(player,playee,k,prob)
|
||||
int *player,*playee,k,*prob;
|
||||
{
|
||||
int newtry[31], newother[31], *r, *q, *p, n, sum, first;
|
||||
int ii, lastwhite, lastbrown;
|
||||
|
||||
*prob = sum = 0;
|
||||
r = player+25;
|
||||
p = newtry;
|
||||
q = newother;
|
||||
while(player<r){
|
||||
*p++= *player++;
|
||||
*q++= *playee++;
|
||||
}
|
||||
q=newtry+31;
|
||||
for(p = newtry+25; p < q; p++) /* zero out spaces for hit pieces */
|
||||
*p = 0;
|
||||
for(n = 0; n < 4; n++){
|
||||
if(moves[k].pos[n] == NIL)
|
||||
break;
|
||||
newtry[moves[k].pos[n]]--;
|
||||
newtry[ii=moves[k].pos[n]+moves[k].mov[n]]++;
|
||||
if(ii<25 && newother[25-ii]==1){
|
||||
newother[25-ii]=0;
|
||||
newother[0]++;
|
||||
if(ii<=15 && level=='e') /* hit if near other's home */
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
for(lastbrown = 0; newother[lastbrown] == 0; lastbrown++);
|
||||
;
|
||||
for(lastwhite = 0; newtry[lastwhite] == 0; lastwhite++)
|
||||
;
|
||||
lastwhite = 25-lastwhite;
|
||||
if(lastwhite<=6 && lastwhite<lastbrown)
|
||||
sum=1000;
|
||||
/* experts running game. */
|
||||
/* first priority is to */
|
||||
/* get all pieces into */
|
||||
/* white's home */
|
||||
if(lastwhite<lastbrown && level=='e' && lastwhite>6) {
|
||||
for(sum = 1000; lastwhite > 6; lastwhite--)
|
||||
sum = sum-lastwhite*newtry[25-lastwhite];
|
||||
}
|
||||
for(first = 0; first < 25; first++)
|
||||
if(newother[first] != 0) /*find other's first piece*/
|
||||
break;
|
||||
q = newtry+25;
|
||||
for(p = newtry+1; p < q;) /* blocked points are good */
|
||||
if(*p++ > 1)
|
||||
sum++;
|
||||
if(first > 5) { /* only stress removing pieces if */
|
||||
/* homeboard cannot be hit */
|
||||
q = newtry+31;
|
||||
p=newtry+25;
|
||||
for(n = 6; p < q; n--)
|
||||
sum += *p++ * n; /*remove pieces, but just barely*/
|
||||
}
|
||||
if(level != 'b'){
|
||||
r = newtry+25-first; /*singles past this point can't be hit*/
|
||||
for(p = newtry+7; p < r; )
|
||||
if(*p++ == 1) /*singles are bad after 1st 6 points if they can be hit*/
|
||||
sum--;
|
||||
q = newtry+3;
|
||||
for(p = newtry; p < q; ) /*bad to be on 1st three points*/
|
||||
sum -= *p++;
|
||||
}
|
||||
|
||||
for(n = 1; n <= 4; n++)
|
||||
*prob += n*getprob(newtry,newother,6*n-5,6*n);
|
||||
return(sum);
|
||||
}
|
||||
instructions()
|
||||
{
|
||||
register fd, r;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
if((fd = open(RULES, 0)) < 0) {
|
||||
fprintf(stderr, "back: cannot open %s\n", RULES);
|
||||
return;
|
||||
}
|
||||
while(r = read(fd, buf, BUFSIZ))
|
||||
write(1, buf, r);
|
||||
}
|
||||
|
||||
getprob(player,playee,start,finish)
|
||||
int *player,*playee,start,finish;
|
||||
{ /*returns the probability (times 102) that any
|
||||
pieces belonging to 'player' and lying between
|
||||
his points 'start' and 'finish' will be hit
|
||||
by a piece belonging to playee
|
||||
*/
|
||||
int k, n, sum;
|
||||
|
||||
sum = 0;
|
||||
for(; start <= finish; start++){
|
||||
if(player[start] == 1){
|
||||
for(k = 1; k <= 12; k++){
|
||||
if((n=25-start-k) < 0)
|
||||
break;
|
||||
if(playee[n] != 0)
|
||||
sum += probability[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
return(sum);
|
||||
}
|
||||
prtbrd()
|
||||
{
|
||||
int k;
|
||||
static char undersc[]="______________________________________________________";
|
||||
|
||||
fprintf(stdout, "White's Home\n%s\r",undersc);
|
||||
for(k = 1; k <= 6; k++)
|
||||
fprintf(stdout, "%4d",k);
|
||||
fprintf(stdout, " ");
|
||||
for(k = 7; k <= 12; k++)
|
||||
fprintf(stdout, "%4d",k);
|
||||
putchar('\n');
|
||||
numline(brown, white, 1, 6);
|
||||
fprintf(stdout, " ");
|
||||
numline(brown, white, 7, 12);
|
||||
putchar('\n');
|
||||
colorline(brown, 'B', white, 'W', 1, 6);
|
||||
fprintf(stdout, " ");
|
||||
colorline(brown, 'B', white, 'W', 7, 12);
|
||||
putchar('\n');
|
||||
if(white[0] != 0)
|
||||
fprintf(stdout, "%28dW\n",white[0]);
|
||||
else
|
||||
putchar('\n');
|
||||
if(brown[0] != 0)
|
||||
fprintf(stdout, "%28dB\n", brown[0]);
|
||||
else
|
||||
putchar('\n');
|
||||
colorline(white, 'W', brown, 'B', 1, 6);
|
||||
fprintf(stdout, " ");
|
||||
colorline(white, 'W', brown, 'B', 7, 12);
|
||||
fprintf(stdout, "\n%s\r",undersc);
|
||||
numline(white, brown, 1, 6);
|
||||
fprintf(stdout, " ");
|
||||
numline(white, brown, 7, 12);
|
||||
putchar('\n');
|
||||
for(k = 24; k >= 19; k--)
|
||||
fprintf(stdout, "%4d",k);
|
||||
fprintf(stdout, " ");
|
||||
for(k = 18; k >= 13; k--)
|
||||
fprintf(stdout, "%4d",k);
|
||||
fprintf(stdout, "\nBrown's Home\n\n\n\n\n");
|
||||
}
|
||||
numline(upcol,downcol,start,fin)
|
||||
int *upcol,*downcol,start,fin;
|
||||
{
|
||||
int k, n;
|
||||
|
||||
for(k = start; k <= fin; k++){
|
||||
if((n = upcol[k]) != 0 || (n = downcol[25-k]) != 0)
|
||||
fprintf(stdout, "%4d", n);
|
||||
else
|
||||
fprintf(stdout, " ");
|
||||
}
|
||||
}
|
||||
colorline(upcol,c1,downcol,c2,start,fin)
|
||||
int *upcol,*downcol,start,fin;
|
||||
char c1,c2;
|
||||
{
|
||||
int k;
|
||||
char c;
|
||||
|
||||
for(k = start; k <= fin; k++){
|
||||
c = ' ';
|
||||
if(upcol[k] != 0)
|
||||
c = c1;
|
||||
if(downcol[25-k] != 0)
|
||||
c = c2;
|
||||
fprintf(stdout, " %c",c);
|
||||
}
|
||||
}
|
176
games/backgammon/common_source/board.c
Normal file
176
games/backgammon/common_source/board.c
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)board.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
static int i, j, k;
|
||||
static char ln[60];
|
||||
|
||||
wrboard () {
|
||||
register int l;
|
||||
static char bl[] =
|
||||
"| | | |\n";
|
||||
static 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;
|
||||
|
||||
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;
|
||||
}
|
158
games/backgammon/common_source/check.c
Normal file
158
games/backgammon/common_source/check.c
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)check.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
getmove () {
|
||||
register 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;
|
||||
|
||||
{
|
||||
register 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);
|
||||
}
|
748
games/backgammon/common_source/fancy.c
Normal file
748
games/backgammon/common_source/fancy.c
Normal file
@ -0,0 +1,748 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)fancy.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#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;
|
||||
|
||||
void addbuf();
|
||||
|
||||
fboard () {
|
||||
register 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 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;
|
||||
|
||||
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 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;
|
||||
|
||||
{
|
||||
register 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;
|
||||
|
||||
{
|
||||
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 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;
|
||||
|
||||
/* 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 */
|
||||
}
|
||||
|
||||
tos () { /* home cursor */
|
||||
curmove (0,0);
|
||||
}
|
||||
|
||||
fancyc (c)
|
||||
register char c; /* character to output */
|
||||
{
|
||||
register 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;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
getcaps (s)
|
||||
register char *s;
|
||||
|
||||
{
|
||||
register char *code; /* two letter code */
|
||||
register char ***cap; /* pointer to cap string */
|
||||
char *bufp; /* pointer to cap buffer */
|
||||
char tentry[1024]; /* temporary uncoded caps buffer */
|
||||
|
||||
tgetent (tentry,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);
|
||||
}
|
65
games/backgammon/common_source/init.c
Normal file
65
games/backgammon/common_source/init.c
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sgtty.h>
|
||||
|
||||
/*
|
||||
* variable initialization.
|
||||
*/
|
||||
|
||||
/* name of executable object programs */
|
||||
char EXEC[] = "/usr/games/backgammon";
|
||||
char TEACH[] = "/usr/games/teachgammon";
|
||||
|
||||
int pnum = 2; /* color of player:
|
||||
-1 = white
|
||||
1 = red
|
||||
0 = both
|
||||
2 = not yet init'ed */
|
||||
int acnt = 0; /* length of args */
|
||||
int aflag = 1; /* flag to ask for rules or instructions */
|
||||
int bflag = 0; /* flag for automatic board printing */
|
||||
int cflag = 0; /* case conversion flag */
|
||||
int hflag = 1; /* flag for cleaning screen */
|
||||
int mflag = 0; /* backgammon flag */
|
||||
int raflag = 0; /* 'roll again' flag for recovered game */
|
||||
int rflag = 0; /* recovered game flag */
|
||||
int tflag = 0; /* cursor addressing flag */
|
||||
int iroll = 0; /* special flag for inputting rolls */
|
||||
int rfl = 0;
|
||||
|
||||
char *color[] = {"White","Red","white","red"};
|
113
games/backgammon/common_source/odds.c
Normal file
113
games/backgammon/common_source/odds.c
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 r2, val;
|
||||
{
|
||||
register 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;
|
||||
|
||||
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 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());
|
||||
}
|
169
games/backgammon/common_source/one.c
Normal file
169
games/backgammon/common_source/one.c
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)one.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
makmove (i)
|
||||
register int i;
|
||||
|
||||
{
|
||||
register 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;
|
||||
|
||||
{
|
||||
register 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;
|
||||
|
||||
{
|
||||
if (d0 != d)
|
||||
swap;
|
||||
return (0);
|
||||
}
|
||||
|
||||
last () {
|
||||
register 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;
|
||||
|
||||
{
|
||||
register int j;
|
||||
|
||||
for (j = i-1; j >= 0; j--)
|
||||
backone(j);
|
||||
}
|
||||
|
||||
backone (i)
|
||||
register 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;
|
||||
}
|
||||
}
|
||||
}
|
180
games/backgammon/common_source/save.c
Normal file
180
games/backgammon/common_source/save.c
Normal file
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
extern int errno;
|
||||
|
||||
static char confirm[] = "Are you sure you want to leave now?";
|
||||
static char prompt[] = "Enter a file name: ";
|
||||
static char exist1[] = "The file '";
|
||||
static char exist2[] =
|
||||
"' already exists.\nAre you sure you want to use this file?";
|
||||
static char cantuse[] = "\nCan't use ";
|
||||
static char saved[] = "This game has been saved on the file '";
|
||||
static char type[] = "'.\nType \"backgammon ";
|
||||
static char rec[] = "\" to recover your game.\n\n";
|
||||
static char cantrec[] = "Can't recover file: ";
|
||||
|
||||
save (n)
|
||||
register int n;
|
||||
|
||||
{
|
||||
register int fdesc;
|
||||
register 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,2)) == -1 && errno == 2) {
|
||||
if ((fdesc = creat (fname,0700)) != -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 ();
|
||||
}
|
||||
|
||||
recover (s)
|
||||
char *s;
|
||||
|
||||
{
|
||||
register int i;
|
||||
int fdesc;
|
||||
|
||||
if ((fdesc = open (s,0)) == -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;
|
||||
}
|
||||
|
||||
norec (s)
|
||||
register char *s;
|
||||
|
||||
{
|
||||
register char *c;
|
||||
|
||||
tflag = 0;
|
||||
writel (cantrec);
|
||||
c = s;
|
||||
while (*c != '\0')
|
||||
writec (*c++);
|
||||
getout ();
|
||||
}
|
477
games/backgammon/common_source/subs.c
Normal file
477
games/backgammon/common_source/subs.c
Normal file
@ -0,0 +1,477 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)subs.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "back.h"
|
||||
|
||||
int buffnum;
|
||||
char outbuff[BUFSIZ];
|
||||
|
||||
static char plred[] = "Player is red, computer is white.";
|
||||
static char plwhite[] = "Player is white, computer is red.";
|
||||
static char nocomp[] = "(No computer play.)";
|
||||
|
||||
char *descr[] = {
|
||||
"Usage: backgammon [-] [n r w b pr pw pb t3a]\n",
|
||||
"\t-\tgets this list\n\tn\tdon't ask for rules or instructions",
|
||||
"\tr\tplayer is red (implies n)\n\tw\tplayer is white (implies n)",
|
||||
"\tb\ttwo players, red and white (implies n)",
|
||||
"\tpr\tprint the board before red's turn",
|
||||
"\tpw\tprint the board before white's turn",
|
||||
"\tpb\tprint the board before both player's turn",
|
||||
"\tterm\tterminal is a term",
|
||||
"\tsfile\trecover saved game from file",
|
||||
0
|
||||
};
|
||||
|
||||
errexit (s)
|
||||
register char *s;
|
||||
{
|
||||
write (2,"\n",1);
|
||||
perror (s);
|
||||
getout();
|
||||
}
|
||||
|
||||
strset (s1,s2)
|
||||
register char *s1, *s2;
|
||||
{
|
||||
while ( (*s1++ = *s2++) != '\0');
|
||||
}
|
||||
|
||||
addbuf (c)
|
||||
register char c;
|
||||
|
||||
{
|
||||
buffnum++;
|
||||
if (buffnum == BUFSIZ) {
|
||||
if (write(1,outbuff,BUFSIZ) != BUFSIZ)
|
||||
errexit ("addbuf (write):");
|
||||
buffnum = 0;
|
||||
}
|
||||
outbuff[buffnum] = c;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
writel (l)
|
||||
register char *l;
|
||||
{
|
||||
#ifdef DEBUG
|
||||
register 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;
|
||||
|
||||
for (i = 4; i > 0; i--) {
|
||||
t = 1;
|
||||
for (j = 0; j<i; j++)
|
||||
t *= 10;
|
||||
if (n > t-1)
|
||||
writec ((n/t)%10+'0');
|
||||
}
|
||||
writec (n%10+'0');
|
||||
}
|
||||
|
||||
gwrite() {
|
||||
register 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;
|
||||
|
||||
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 */
|
||||
{
|
||||
register char c;
|
||||
register 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;
|
||||
{
|
||||
writel ("Blot hit on ");
|
||||
wrint (i);
|
||||
writec ('.');
|
||||
writec ('\n');
|
||||
}
|
||||
|
||||
nexturn () {
|
||||
register 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 (arg)
|
||||
register char ***arg;
|
||||
|
||||
{
|
||||
register char **s;
|
||||
|
||||
/* process arguments here. dashes are ignored, nbrw are ignored
|
||||
if the game is being recovered */
|
||||
|
||||
s = *arg;
|
||||
while (s[0][0] == '-') {
|
||||
switch (s[0][1]) {
|
||||
|
||||
/* don't ask if rules or instructions needed */
|
||||
case 'n':
|
||||
if (rflag)
|
||||
break;
|
||||
aflag = 0;
|
||||
args[acnt++] = 'n';
|
||||
break;
|
||||
|
||||
/* player is both read and white */
|
||||
case 'b':
|
||||
if (rflag)
|
||||
break;
|
||||
pnum = 0;
|
||||
aflag = 0;
|
||||
args[acnt++] = 'b';
|
||||
break;
|
||||
|
||||
/* player is red */
|
||||
case 'r':
|
||||
if (rflag)
|
||||
break;
|
||||
pnum = -1;
|
||||
aflag = 0;
|
||||
args[acnt++] = 'r';
|
||||
break;
|
||||
|
||||
/* player is white */
|
||||
case 'w':
|
||||
if (rflag)
|
||||
break;
|
||||
pnum = 1;
|
||||
aflag = 0;
|
||||
args[acnt++] = 'w';
|
||||
break;
|
||||
|
||||
/* print board after move according to following character */
|
||||
case 'p':
|
||||
if (s[0][2] != 'r' && s[0][2] != 'w' && s[0][2] != 'b')
|
||||
break;
|
||||
args[acnt++] = 'p';
|
||||
args[acnt++] = s[0][2];
|
||||
if (s[0][2] == 'r')
|
||||
bflag = 1;
|
||||
if (s[0][2] == 'w')
|
||||
bflag = -1;
|
||||
if (s[0][2] == 'b')
|
||||
bflag = 0;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
if (s[0][2] == '\0') { /* get terminal caps */
|
||||
s++;
|
||||
tflag = getcaps (*s);
|
||||
} else
|
||||
tflag = getcaps (&s[0][2]);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
s++;
|
||||
/* recover file */
|
||||
recover (s[0]);
|
||||
break;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (s[0] != 0)
|
||||
recover(s[0]);
|
||||
}
|
||||
|
||||
init () {
|
||||
register 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");
|
||||
}
|
||||
|
||||
getout () {
|
||||
/* go to bottom of screen */
|
||||
if (tflag) {
|
||||
curmove (23,0);
|
||||
cline();
|
||||
} else
|
||||
writec ('\n');
|
||||
|
||||
/* fix terminal status */
|
||||
fixtty (old);
|
||||
exit();
|
||||
}
|
||||
roll () {
|
||||
register char c;
|
||||
register int row;
|
||||
register 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;
|
||||
}
|
308
games/backgammon/common_source/table.c
Normal file
308
games/backgammon/common_source/table.c
Normal file
@ -0,0 +1,308 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
char *help2[] = {
|
||||
" Enter moves as <s>-<f> or <s>/<r> where <s> is the starting",
|
||||
"position, <f> is the finishing position, and <r> is the roll.",
|
||||
"Remember, each die roll must be moved separately.",
|
||||
0
|
||||
};
|
||||
|
||||
struct state {
|
||||
char ch;
|
||||
int fcode;
|
||||
int newst;
|
||||
};
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
{
|
||||
register 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;
|
||||
|
||||
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);
|
||||
}
|
15
games/backgammon/teachgammon/Makefile
Normal file
15
games/backgammon/teachgammon/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
PROG= teachgammon
|
||||
CFLAGS+=-DV7 -I${.CURDIR}/../common_source
|
||||
SRCS= allow.c board.c check.c data.c fancy.c init.c odds.c one.c save.c \
|
||||
subs.c table.c teach.c ttext1.c ttext2.c tutor.c
|
||||
DPADD= ${LIBTERM} ${LIBCOMPAT}
|
||||
LDADD= -ltermcap -lcompat
|
||||
HIDEGAME=hidegame
|
||||
NOMAN= noman
|
||||
|
||||
.PATH: ${.CURDIR}/../common_source
|
||||
|
||||
.include "../../Makefile.inc"
|
||||
.include <bsd.prog.mk>
|
315
games/backgammon/teachgammon/data.c
Normal file
315
games/backgammon/teachgammon/data.c
Normal file
@ -0,0 +1,315 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)data.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "tutor.h"
|
||||
|
||||
int maxmoves = 23;
|
||||
|
||||
char *text0[] = {
|
||||
"To start the game, I roll a 3, and you roll a 1. This means",
|
||||
"that I get to start first. I move 8-5,6-5 since this makes a",
|
||||
"new point and helps to trap your back men on 1. You should be",
|
||||
"able to do a similar move with your roll.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text1[] = {
|
||||
"Now you shall see a move using doubles. I just rolled double",
|
||||
"5's. I will move two men from position 13 to position 3. The",
|
||||
"notation for this is 13-8,13-8,8-3,8-3. You will also roll dou-",
|
||||
"bles, but you will be able to make a much stronger move.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text2[] = {
|
||||
"Excellent! As you can see, you are beginning to develop a wall",
|
||||
"which is trapping my men on position 24. Also, moving your back",
|
||||
"men forward not only improves your board position safely, but it",
|
||||
"thwarts my effort to make a wall.",
|
||||
"",
|
||||
"My roll now is 5 6. Normally, I would use that roll to move from",
|
||||
"position 24 to position 13 (24-18-13), but your new point prevents",
|
||||
"that. Instead, I am forced to move from 13 to 2, where my man is",
|
||||
"open but cannot be hit.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text3[] = {
|
||||
"As you can see, although you left a man open, it is a rela-",
|
||||
"tively safe move to an advantageous position, which might help",
|
||||
"you make a point later. Only two rolls (4 5 or 5 4) will allow",
|
||||
"me to hit you. With an unprecedented amount of luck, I happen",
|
||||
"to roll a 4 5 and hit you as just mentioned.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text4[] = {
|
||||
"You're pretty lucky yourself, you know. I follow by rolling 2 3",
|
||||
"and moving 25-22,24-22, forming a new point.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text5[] = {
|
||||
"Not a spectacular move, but a safe one. I follow by rolling 6 1.",
|
||||
"I decide to use this roll to move 22-16,16-17. It leaves me with",
|
||||
"one man still open, but the blot is farther back on the board, and",
|
||||
"would suffer less of a loss by being hit.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text6[] = {
|
||||
"By moving your two men from 17 to 20, you lessen my chance of",
|
||||
"getting my man off the board. In fact, the odds are 5 to 4",
|
||||
"against me getting off. I roll with the odds and helplessly",
|
||||
"receive a 3 5.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text7[] = {
|
||||
"Note that the blot on 7 cannot be hit unless I get off the bar",
|
||||
"and have a 1 or a 6 left over, and doing so will leave two of",
|
||||
"my men open. Also, the blot on 16 cannot be hit at all! With",
|
||||
"a sigh of frustration, I roll double 6's and remain immobile.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text8[] = {
|
||||
"See, you did not get hit and, you got to 'cover up' your open men.",
|
||||
"Quite an accomplishment. Finally, I get off the bar by rolling",
|
||||
"6 2 and moving 25-23,23-17.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text9[] = {
|
||||
"My venture off the bar did not last long. However, I got lucky",
|
||||
"and rolled double 1's, allowing me to move 0-1,1-2,15-14,15-14.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text10[] = {
|
||||
"You are improving your position greatly and safely, and are well",
|
||||
"on the way to winning the game. I roll a 6 2 and squeak past",
|
||||
"your back man. Now the game becomes a race to the finish.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text11[] = {
|
||||
"Now that it is merely a race, you are trying to get as many men",
|
||||
"as possible into the inner table, so you can start removing them.",
|
||||
"I roll a 3 4 and move my two men farthest back to position 11",
|
||||
"(15-11,14-11).",
|
||||
0
|
||||
};
|
||||
|
||||
char *text12[] = {
|
||||
"The race is still on, and you have seem to be doing all right.",
|
||||
"I roll 6 1 and move 14-8,13-12.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text13[] = {
|
||||
"Notice that you get to remove men the instant you have all of",
|
||||
"them at your inner table, even if it is the middle of a turn.",
|
||||
"I roll 1 2 and move 13-11,12-11.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text14[] = {
|
||||
"Although you could have removed a man, this move illustrates two",
|
||||
"points: 1) You never have to remove men, and 2) You should try",
|
||||
"to spread out your men on your inner table. Since you have one",
|
||||
"man on each position, you should be able to remove at least two",
|
||||
"men next turn. I roll 2 5 and move 8-6,11-6.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text15[] = {
|
||||
"This time you were able to remove men. I roll 3 4 and move",
|
||||
"11-7,11-8. The race continues.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text16[] = {
|
||||
"More holes are opening up in your inner table, but you are",
|
||||
"still very much ahead. If we were doubling, you would have",
|
||||
"doubled long ago. I roll 2 6 and move 8-6,11-5.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text17[] = {
|
||||
"It pays to spread out your men. I roll 3 5 and move 7-4,8-3.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text18[] = {
|
||||
"You can only remove some men, but you spread out more and",
|
||||
"more, in order to be able to remove men more efficiently.",
|
||||
"I roll double 3's, which help, but not that much. I move",
|
||||
"8-5,3-0,3-0,3-0.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text19[] = {
|
||||
"I roll 1 4 and move 5-4,4-0.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text20[] = {
|
||||
"You are now nicely spread out to win a game. I roll 5 6 and",
|
||||
"move 5-0,6-0.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text21[] = {
|
||||
"Any minute now. Just a few short steps from victory. I roll",
|
||||
"2 4 and move 6-4,4-0.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text22[] = {
|
||||
"It looks pretty hopeless for me, but I play on, rolling 1 3 and",
|
||||
"moving 4-3,3-0.",
|
||||
0
|
||||
};
|
||||
|
||||
char *text23[] = {
|
||||
"Congratulations! You just won a game of backgammon against the",
|
||||
"computer! You will now be able to play a game, but remember,",
|
||||
"when you start playing, that doubling will be enabled, which",
|
||||
"will add another factor to the game... Good luck!!",
|
||||
"",
|
||||
0
|
||||
};
|
||||
|
||||
struct situatn test[] = {
|
||||
{
|
||||
{0,2,0,0,0,0,-5,0,-3,0,0,0,5,-5,0,0,0,3,0,5,0,0,0,0,-2,0},
|
||||
3, 1, {8,6,0,0}, {5,5,0,0}, 4, 2, text0
|
||||
},
|
||||
{
|
||||
{0,2,0,0,0,-2,-4,0,-2,0,0,0,5,-5,0,0,0,2,0,4,0,2,0,0,-2,0},
|
||||
5, 5, {13,13,8,8}, {8,8,3,3}, 6, 6, text1
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,2,-2,0,0,0,3,-3,0,0,0,2,2,4,0,2,0,0,-2,0},
|
||||
6, 5, {13,8,0,0}, {8,2,0,0}, 1, 2, text2
|
||||
},
|
||||
{
|
||||
{0,0,-1,-2,0,-2,-4,2,-2,0,0,0,2,-2,0,1,0,2,2,4,0,2,0,0,-2,0},
|
||||
4, 5, {24,20,0,0}, {20,15,0,0}, 2, 5, text3
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,3,-2,0,0,0,2,-2,0,-1,0,2,2,4,0,2,0,0,-1,-1},
|
||||
2, 3, {25,24,0,0}, {22,22,0,0}, 4, 1, text4
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,2,-2,0,0,0,3,-2,0,-1,0,2,2,4,0,2,-2,0,0,0},
|
||||
6, 1, {22,16,0,0}, {16,15,0,0}, 3, 3, text5
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,2,-2,0,0,0,3,-2,0,-2,0,0,2,2,2,2,2,0,0,-1},
|
||||
3, 5, {0,0,0,0}, {0,0,0,0}, 5, 4, text6
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,1,-2,0,0,0,3,-2,0,-2,1,0,2,2,2,2,2,0,0,-1},
|
||||
6, 6, {0,0,0,0}, {0,0,0,0}, 3, 6, text7
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,0,-2,0,0,0,3,-2,0,-2,2,0,2,2,2,2,2,0,0,-1},
|
||||
2, 6, {25,23,0,0}, {23,17,0,0}, 5, 1, text8
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,0,-2,0,0,0,2,-2,0,-2,2,0,3,2,2,2,2,0,0,-1},
|
||||
1, 1, {25,24,15,15}, {24,23,14,14}, 4, 6, text9
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,0,-2,0,0,0,0,-2,-2,0,3,0,4,2,2,2,2,-1,0,0},
|
||||
6, 2, {23,17,0,0}, {17,15,0,0}, 1, 3, text10
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,0,-2,0,0,0,0,-2,-2,-1,2,0,3,4,2,2,2,0,0,0},
|
||||
4, 3, {15,14,0,0}, {11,11,0,0}, 5, 3, text11
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,0,-2,0,0,-2,0,-2,-1,0,0,0,3,5,2,3,2,0,0,0},
|
||||
6, 1, {14,13,0,0}, {8,12,0,0}, 4, 4, text12
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,0,-3,0,0,-2,-1,-1,0,0,0,0,0,5,2,2,5,0,0,0},
|
||||
2, 1, {13,12,0,0}, {11,11,0,0}, 2, 1, text13
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-4,0,-3,0,0,-4,0,0,0,0,0,0,0,5,2,2,3,1,1,0},
|
||||
2, 5, {8,11,0,0}, {6,6,0,0}, 6, 3, text14
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-6,0,-2,0,0,-3,0,0,0,0,0,0,0,4,2,2,2,1,1,0},
|
||||
4, 3, {11,11,0,0}, {7,8,0,0}, 2, 5, text15
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-2,-6,-1,-3,0,0,-1,0,0,0,0,0,0,0,4,1,2,2,0,1,0},
|
||||
2, 6, {8,11,0,0}, {6,5,0,0}, 6, 1, text16
|
||||
},
|
||||
{
|
||||
{0,0,0,-2,0,-3,-7,-1,-2,0,0,0,0,0,0,0,0,0,0,3,1,2,2,0,0,0},
|
||||
5, 3, {8,7,0,0}, {3,4,0,0}, 5, 2, text17
|
||||
},
|
||||
{
|
||||
{0,0,0,-3,-1,-3,-7,0,-1,0,0,0,0,0,0,0,0,0,0,3,0,1,2,1,0,0},
|
||||
3, 3, {8,3,3,3}, {5,0,0,0}, 1, 6, text18
|
||||
},
|
||||
{
|
||||
{0,0,0,0,-1,-4,-7,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,1,0,0},
|
||||
1, 4, {4,5,0,0}, {0,4,0,0}, 2, 3, text19
|
||||
},
|
||||
{
|
||||
{0,0,0,0,-1,-3,-7,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0},
|
||||
5, 6, {6,5,0,0}, {0,0,0,0}, 1, 4, text20
|
||||
},
|
||||
{
|
||||
{0,0,0,0,-1,-2,-6,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0},
|
||||
2, 4, {4,6,0,0}, {0,4,0,0}, 6, 2, text21
|
||||
},
|
||||
{
|
||||
{0,0,0,0,-1,-2,-5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0},
|
||||
3, 1, {4,3,0,0}, {3,0,0,0}, 4, 3, text22
|
||||
},
|
||||
{
|
||||
{0,0,0,0,0,-2,-5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
|
||||
0, 0, {0,0,0,0}, {0,0,0,0}, 0, 0, text23
|
||||
}
|
||||
};
|
166
games/backgammon/teachgammon/teach.c
Normal file
166
games/backgammon/teachgammon/teach.c
Normal file
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 "back.h"
|
||||
|
||||
char *hello[];
|
||||
char *list[];
|
||||
char *intro1[];
|
||||
char *intro2[];
|
||||
char *moves[];
|
||||
char *remove[];
|
||||
char *hits[];
|
||||
char *endgame[];
|
||||
char *doubl[];
|
||||
char *stragy[];
|
||||
char *prog[];
|
||||
char *lastch[];
|
||||
|
||||
extern char ospeed; /* tty output speed for termlib */
|
||||
|
||||
char *helpm[] = {
|
||||
"\nEnter a space or newline to roll, or",
|
||||
" b to display the board",
|
||||
" d to double",
|
||||
" q to quit\n",
|
||||
0
|
||||
};
|
||||
|
||||
char *contin[] = {
|
||||
"",
|
||||
0
|
||||
};
|
||||
|
||||
main (argc,argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
{
|
||||
register int i;
|
||||
|
||||
signal (2,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"));
|
||||
#ifdef V7
|
||||
while (*++argv != 0)
|
||||
#else
|
||||
while (*++argv != -1)
|
||||
#endif
|
||||
getarg (&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() {
|
||||
if (tflag)
|
||||
clear();
|
||||
else
|
||||
writec ('\n');
|
||||
fixtty(old);
|
||||
execl (EXEC,"backgammon",args,"n",0);
|
||||
writel ("Help! Backgammon program is missing\007!!\n");
|
||||
exit (-1);
|
||||
}
|
184
games/backgammon/teachgammon/ttext1.c
Normal file
184
games/backgammon/teachgammon/ttext1.c
Normal file
@ -0,0 +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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)ttext1.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
char *opts = " QIMRHEDSPT";
|
||||
char *prompt = "-->";
|
||||
|
||||
char *list[] = {
|
||||
"\n\n\tI\tIntroduction to Backgammon",
|
||||
"\tM\tMoves and Points",
|
||||
"\tR\tRemoving Men from the Board",
|
||||
"\tH\tHitting Blots",
|
||||
"\tE\tEnding the Game and Scoring",
|
||||
"\tD\tDoubling",
|
||||
"\tS\tStrategy",
|
||||
"\tP\tThe Program and How to Use It",
|
||||
"\nalso, you can type:",
|
||||
"\t?\tto get this list",
|
||||
"\tQ\tto go start playing",
|
||||
"\tT\tto go straight to the tutorial",
|
||||
0
|
||||
};
|
||||
|
||||
char *hello[] = {
|
||||
"\n\032 These rules consist of text describing how to play Backgammon",
|
||||
"followed by a tutorial session where you play a practice game",
|
||||
"against the computer. When using this program, think carefuly",
|
||||
"before typing, since it reacts as soon as you type something. In",
|
||||
"addition, the program presents text output, such as these rules,",
|
||||
"in small blocks that will not roll off the top of the screen.",
|
||||
"Frequently, you will see the characters '-->' indicating that the",
|
||||
"program is waiting for you to finish reading, and will continue",
|
||||
"printing when you type a space or newline. Also, the rules are",
|
||||
"divided into sections, and although you should read them in or-",
|
||||
"der, you can go directly to any of them by typing one of the fol-",
|
||||
"lowing letters:",
|
||||
"(Remember to hit a space or a newline to continue.)",
|
||||
"",
|
||||
0
|
||||
};
|
||||
|
||||
char *intro1[] = {
|
||||
"\nIntroduction:",
|
||||
"\n Backgammon is a game involving the skill of two players and",
|
||||
"the luck of two dice. There are two players, red and white, and",
|
||||
"each player gets fifteen men. The object of the game is to re-",
|
||||
"move all your men from the board before the opponent does. The",
|
||||
"board consists of twenty-four positions, a 'bar' and a 'home' for",
|
||||
"each player. It looks like this:",
|
||||
"",
|
||||
0};
|
||||
|
||||
char *intro2[] = {
|
||||
"",
|
||||
"\n Although not indicated on the board, the players' homes are",
|
||||
"located just to the right of the board. A player's men are placed",
|
||||
"there when they are removed from the board. The board you just",
|
||||
"saw was in it's initial position. All games start with the board",
|
||||
"looking like this. Notice that red's pieces are represented by the",
|
||||
"letter 'r' and white's pieces are represented by the letter 'w'.",
|
||||
"Also, a position may have zero or more pieces on it, e.g. posi-",
|
||||
"tion 12 has five red pieces on it, while position 11 does not",
|
||||
"have any pieces of either color.",
|
||||
"",
|
||||
0};
|
||||
|
||||
char *moves[] = {
|
||||
"\nMoves and Points:",
|
||||
"\n Moves are made along the positions on the board according to",
|
||||
"their numbers. Red moves in the positive direction (clockwise",
|
||||
"from 1 to 24), and white moves in the negative direction (coun-",
|
||||
"terclockwise from 24 to 1).",
|
||||
"\n A turn consists of rolling the dice, and moving the number of",
|
||||
"positions indicated on each die. The two numbers can be used to",
|
||||
"move one man the sum of the two rolls, or two men the number on",
|
||||
"each individual die. For example, if red rolled 6 3 at the start",
|
||||
"of the game, he might move a man from 1 to 7 to 10, using both",
|
||||
"dice for one man, or he might move two men from position 12, one",
|
||||
"to 15 and one to 18. (Red did not have to choose two men start-",
|
||||
"ing from the same position.) In addition, doubles are treated",
|
||||
"specially in backgammon. When a player rolls doubles, he gets to",
|
||||
"move as if he had four dice instead of two. For instance, if you",
|
||||
"rolled double 2's, you could move one man eight positions, four",
|
||||
"men two positions each, or any permutation in between.",
|
||||
"",
|
||||
"\n However, there are certain limitations, called 'points.' A",
|
||||
"player has a point when he has two or more men on the same posi-",
|
||||
"tion. This gives him custody of that position, and his opponent",
|
||||
"cannot place his men there, even if passing through on the way to",
|
||||
"another position. When a player has six points in a row, it is",
|
||||
"called a 'wall,' since any of his opponent's men behind the wall",
|
||||
"cannot pass it and are trapped, at least for the moment. Notice",
|
||||
"that this could mean that a player could not use part or all of",
|
||||
"his roll. However, he must use as much of his roll as possible.",
|
||||
"",
|
||||
0};
|
||||
|
||||
char *remove[] = {
|
||||
"\nRemoving Men from the Board:",
|
||||
"\n The most important part of the game is removing men, since",
|
||||
"that is how you win the game. Once a man is removed, he stays",
|
||||
"off the board for the duration of the game. However, a player",
|
||||
"cannot remove men until all his men are on his 'inner table,' or",
|
||||
"the last six positions of the board (19-24 for red, 6-1 for",
|
||||
"white).",
|
||||
"\n To get off the board, a player must roll the exact number to",
|
||||
"get his man one position past the last position on the board, or",
|
||||
"his 'home.' Hence, if red wanted to remove a man from position",
|
||||
"23, he would have to roll a 2, anything else would be used for",
|
||||
"another man, or for another purpose. However, there is one ex-",
|
||||
"ception. If the player rolling has no men far enough to move the",
|
||||
"roll made, he may move his farthest man off the board. For exam-",
|
||||
"ple, if red's farthest man back was on position 21, he could re-",
|
||||
"move men from that position if he rolled a 5 or a 6, as well as a",
|
||||
"4. Since he does not have men on 20 (where he could use a 5) or",
|
||||
"on 19 (where he could use a 6), he can use these rolls for posi-",
|
||||
"tion 21. A player never has to remove men, but he must make as",
|
||||
"many moves as possible.",
|
||||
"",
|
||||
0};
|
||||
|
||||
char *hits[] = {
|
||||
"\nHitting Blots:",
|
||||
"\n Although two men on a position form an impenetrable point, a",
|
||||
"lone man is not so secure. Such a man is called a 'blot' and has",
|
||||
"the potential of getting hit by an opposing man. When a player's",
|
||||
"blot is hit, he is placed on the bar, and the first thing that",
|
||||
"player must do is move the man off the bar. Such moves are",
|
||||
"counted as if the bar is one position behind the first position",
|
||||
"on the board. Thus if red has a man on the bar and rolls 2 3, he",
|
||||
"must move the man on the bar to position 2 or 3 before moving any",
|
||||
"other man. If white had points on positions 2 and 3, then red",
|
||||
"would forfeit his turn. Being on the bar is a very bad position,",
|
||||
"for often a player can lose many turns trying to move off the",
|
||||
"bar, as well as being set back the full distance of the board.",
|
||||
"",
|
||||
0};
|
||||
|
||||
char *endgame[] = {
|
||||
"\nEnding the Game and Scoring:",
|
||||
"\n Winning a game usually wins one point, the normal value of a",
|
||||
"game. However, if the losing player has not removed any men yet,",
|
||||
"then the winning player wins double the game value, called a",
|
||||
"'gammon.' If the losing player has a player on the bar or on the",
|
||||
"winner's inner table, then the winner gets triple the game value,",
|
||||
"which is called a 'backgammon.' (So that's where the name comes",
|
||||
"from!)",
|
||||
"",
|
||||
0};
|
193
games/backgammon/teachgammon/ttext2.c
Normal file
193
games/backgammon/teachgammon/ttext2.c
Normal file
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)ttext2.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "back.h"
|
||||
|
||||
char *prompt, *list, *opts;
|
||||
|
||||
char *doubl[] = {
|
||||
"\nDoubling:",
|
||||
"\n If a player thinks he is in a good position, he may double the",
|
||||
"value of the game. However, his opponent may not accept the pro-",
|
||||
"posal and forfeit the game before the price gets too high. A",
|
||||
"player must double before he rolls, and once his double has been",
|
||||
"accepted, he cannot double again, until his opponent has doubled.",
|
||||
"Thus, unless the game swings back and forth in advantage between",
|
||||
"the two players a great deal, the value of the game should be",
|
||||
"low. At any rate, the value of the game will never go above 64,",
|
||||
"or six doubles. However, if a player wins a backgammon at 64",
|
||||
"points, he wins 192 points!",
|
||||
"",
|
||||
0};
|
||||
|
||||
char *stragy[] = {
|
||||
"\nStrategy:",
|
||||
"\n Some general hints when playing: Try not to leave men open",
|
||||
"unless absolutely necessary. Also, it is good to make as many",
|
||||
"points as possible. Often, two men from different positions can",
|
||||
"be brought together to form a new point. Although walls (six",
|
||||
"points in a row) are difficult to form, many points nestled close-",
|
||||
"ly together produce a formidable barrier. Also, while it is good",
|
||||
"to move back men forward, doing so lessens the opportunity for you",
|
||||
"to hit men. Finally, remember that once the two player's have",
|
||||
"passed each other on the board, there is no chance of either team",
|
||||
"being hit, so the game reduces to a race off the board. Addi-",
|
||||
"tional hints on strategy are presented in the practice game.",
|
||||
"",
|
||||
0};
|
||||
|
||||
char *prog[] = {
|
||||
"\nThe Program and How It Works:",
|
||||
"\n A general rule of thumb is when you don't know what to do,",
|
||||
"type a question mark, and you should get some help. When it is",
|
||||
"your turn, only your color will be printed out, with nothing",
|
||||
"after it. You may double by typing a 'd', but if you type a",
|
||||
"space or newline, you will get your roll. (Remember, you must",
|
||||
"double before you roll.) Also, typing a 'r' will reprint the",
|
||||
"board, and a 'q' will quit the game. The program will type",
|
||||
"'Move:' when it wants your move, and you may indicate each die's",
|
||||
"move with <s>-<f>, where <s> is the starting position and <f> is",
|
||||
"the finishing position, or <s>/<r> where <r> is the roll made.",
|
||||
"<s>-<f1>-<f2> is short for <s>-<f1>,<f1>-<f2> and <s>/<r1><r2> is",
|
||||
"short for <s>/<r1>,<s>/<r2>. Moves may be separated by a comma",
|
||||
"or a space.",
|
||||
"",
|
||||
"\n While typing, any input which does not make sense will not be",
|
||||
"echoed, and a bell will sound instead. Also, backspacing and",
|
||||
"killing lines will echo differently than normal. You may examine",
|
||||
"the board by typing a 'r' if you have made a partial move, or be-",
|
||||
"fore you type a newline, to see what the board looks like. You",
|
||||
"must end your move with a newline. If you cannot double, your",
|
||||
"roll will always be printed, and you will not be given the oppor-",
|
||||
"tunity to double. Home and bar are represented by the appropri-",
|
||||
"ate number, 0 or 25 as the case may be, or by the letters 'h' or",
|
||||
"'b' as appropriate. You may also type 'r' or 'q' when the program",
|
||||
"types 'Move:', which has the same effect as above. Finally, you",
|
||||
"will get to decide if you want to play red or white (or both if you",
|
||||
"want to play a friend) at the beginning of the session, and you",
|
||||
"will not get to change your mind later, since the computer keeps",
|
||||
"score.",
|
||||
"",
|
||||
0};
|
||||
|
||||
char *lastch[] = {
|
||||
"\nTutorial (Practice Game):",
|
||||
"\n This tutorial, for simplicity's sake, will let you play one",
|
||||
"predetermined game. All the rolls have been pre-arranged, and",
|
||||
"only one response will let you advance to the next move.",
|
||||
"Although a given roll will may have several legal moves, the tu-",
|
||||
"torial will only accept one (not including the same moves in a",
|
||||
"different order), claiming that that move is 'best.' Obviously,",
|
||||
"a subjective statement. At any rate, be patient with it and have",
|
||||
"fun learning about backgammon. Also, to speed things up a lit-",
|
||||
"tle, doubling will not take place in the tutorial, so you will",
|
||||
"never get that opportunity, and quitting only leaves the tutori-",
|
||||
"al, not the game. You will still be able to play backgammon",
|
||||
"after quitting.",
|
||||
"\n This is your last chance to look over the rules before the tu-",
|
||||
"torial starts.",
|
||||
"",
|
||||
0};
|
||||
|
||||
text (txt)
|
||||
char **txt;
|
||||
|
||||
{
|
||||
char **begin;
|
||||
char *a;
|
||||
char b;
|
||||
char *c;
|
||||
int i;
|
||||
|
||||
fixtty (noech);
|
||||
begin = txt;
|
||||
while (*txt) {
|
||||
a = *(txt++);
|
||||
if (*a != '\0') {
|
||||
c = a;
|
||||
for (i = 0; *(c++) != '\0'; i--);
|
||||
writel (a);
|
||||
writec ('\n');
|
||||
} else {
|
||||
fixtty (raw);
|
||||
writel (prompt);
|
||||
for (;;) {
|
||||
if ((b = readc()) == '?') {
|
||||
if (tflag) {
|
||||
if (begscr) {
|
||||
curmove (18,0);
|
||||
clend();
|
||||
} else
|
||||
clear();
|
||||
} else
|
||||
writec ('\n');
|
||||
text (list);
|
||||
writel (prompt);
|
||||
continue;
|
||||
}
|
||||
i = 0;
|
||||
if (b == '\n')
|
||||
break;
|
||||
while (i < 11) {
|
||||
if (b == opts[i])
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
if (i == 11)
|
||||
writec ('\007');
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (tflag) {
|
||||
if (begscr) {
|
||||
curmove (18,0);
|
||||
clend();
|
||||
} else
|
||||
clear();
|
||||
} else
|
||||
writec ('\n');
|
||||
if (i)
|
||||
return(i);
|
||||
fixtty (noech);
|
||||
if (tflag)
|
||||
curmove (curr,0);
|
||||
begin = txt;
|
||||
}
|
||||
}
|
||||
fixtty (raw);
|
||||
return (0);
|
||||
}
|
155
games/backgammon/teachgammon/tutor.c
Normal file
155
games/backgammon/teachgammon/tutor.c
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 char *finis[];
|
||||
|
||||
extern struct situatn test[];
|
||||
|
||||
static char better[] = "That is a legal move, but there is a better one.\n";
|
||||
|
||||
tutor () {
|
||||
register 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;
|
||||
|
||||
r = curr;
|
||||
c = curc;
|
||||
for (j = r+1; j < 24; j++) {
|
||||
curmove (j,0);
|
||||
cline();
|
||||
}
|
||||
curmove (r,c);
|
||||
}
|
||||
|
||||
brdeq (b1,b2)
|
||||
register int *b1, *b2;
|
||||
|
||||
{
|
||||
register int *e;
|
||||
|
||||
e = b1+26;
|
||||
while (b1 < e)
|
||||
if (*b1++ != *b2++)
|
||||
return(0);
|
||||
return(1);
|
||||
}
|
45
games/backgammon/teachgammon/tutor.h
Normal file
45
games/backgammon/teachgammon/tutor.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* @(#)tutor.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
struct situatn {
|
||||
int brd[26];
|
||||
int roll1;
|
||||
int roll2;
|
||||
int mp[4];
|
||||
int mg[4];
|
||||
int new1;
|
||||
int new2;
|
||||
char *(*com[8]);
|
||||
};
|
12
games/battlestar/Makefile
Normal file
12
games/battlestar/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
PROG= battlestar
|
||||
SRCS= battlestar.c com1.c com2.c com3.c com4.c com5.c com6.c com7.c \
|
||||
init.c cypher.c getcom.c parse.c room.c save.c fly.c misc.c \
|
||||
globals.c dayfile.c nightfile.c dayobjs.c nightobjs.c words.c
|
||||
MAN6= battlestar.6
|
||||
DPADD= ${LIBCURSES} ${LIBTERMCAP} ${LIBCOMPAT}
|
||||
LDADD= -lcurses -ltermlib -lcompat
|
||||
HIDEGAME=hidegame
|
||||
|
||||
.include <bsd.prog.mk>
|
164
games/battlestar/battlestar.6
Normal file
164
games/battlestar/battlestar.6
Normal file
@ -0,0 +1,164 @@
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)battlestar.6 8.1 (Berkeley) 5/31/93
|
||||
.\"
|
||||
.TH BATTLESTAR 6 "May 31, 1993
|
||||
.UC 6
|
||||
.SH NAME
|
||||
battlestar \- a tropical adventure game
|
||||
.SH SYNOPSIS
|
||||
.B battlestar
|
||||
[
|
||||
.B -r (recover a saved game)
|
||||
]
|
||||
.br
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.I Battlestar
|
||||
is an adventure game in the classic style. However, It's slightly less
|
||||
of a
|
||||
puzzle and more a game of exploration. There are a few magical words
|
||||
in the game, but on the whole, simple English
|
||||
should suffice to make one's desires understandable to the parser.
|
||||
.SH "THE SETTING"
|
||||
In the days before the darkness came, when battlestars ruled the
|
||||
heavens...
|
||||
.br
|
||||
.nf
|
||||
|
||||
Three He made and gave them to His daughters,
|
||||
Beautiful nymphs, the goddesses of the waters.
|
||||
One to bring good luck and simple feats of wonder,
|
||||
Two to wash the lands and churn the waves asunder,
|
||||
Three to rule the world and purge the skies with thunder.
|
||||
|
||||
.fi
|
||||
.PP
|
||||
In those times great wizards were known and their powers were beyond
|
||||
belief. They could take any object from thin air, and, uttering the
|
||||
word `su' could disappear.
|
||||
.PP
|
||||
In those times men were known for their lust of gold and desire to
|
||||
wear fine weapons. Swords and coats of mail were fashioned that could
|
||||
withstand a laser blast.
|
||||
.PP
|
||||
But when the darkness fell, the rightful reigns were toppled. Swords
|
||||
and helms and heads of state went rolling across the grass. The entire
|
||||
fleet of battlestars was reduced to a single ship.
|
||||
.SH "SAMPLE COMMANDS"
|
||||
.nf
|
||||
|
||||
take --- take an object
|
||||
drop --- drop an object
|
||||
|
||||
wear --- wear an object you are holding
|
||||
draw --- carry an object you are wearing
|
||||
|
||||
puton --- take an object and wear it
|
||||
take off -- draw an object and drop it
|
||||
|
||||
throw <object> <direction>
|
||||
|
||||
! <shell esc>
|
||||
|
||||
.fi
|
||||
.SH "IMPLIED OBJECTS"
|
||||
.nf
|
||||
|
||||
>-: take watermelon
|
||||
watermelon:
|
||||
Taken.
|
||||
>-: eat
|
||||
watermelon:
|
||||
Eaten.
|
||||
>-: take knife and sword and apple, drop all
|
||||
knife:
|
||||
Taken.
|
||||
broadsword:
|
||||
Taken.
|
||||
apple:
|
||||
Taken.
|
||||
knife:
|
||||
Dropped.
|
||||
broadsword:
|
||||
Dropped.
|
||||
apple:
|
||||
Dropped.
|
||||
>-: get
|
||||
knife:
|
||||
Taken.
|
||||
|
||||
.fi
|
||||
.PP
|
||||
Notice that the "shadow" of the next word stays around if you
|
||||
want to take advantage of it. That is, saying "take knife" and then
|
||||
"drop"
|
||||
will drop the knife you just took.
|
||||
.SH "SCORE & INVEN"
|
||||
The two commands "score" and "inven" will print out your current status
|
||||
in
|
||||
the game.
|
||||
.SH "SAVING A GAME"
|
||||
The command "save" will save your game in a file called "Bstar." You
|
||||
can
|
||||
recover a saved game by using the "-r" option when you start up the
|
||||
game.
|
||||
.SH DIRECTIONS
|
||||
The compass directions N, S, E, and W can be used if you have a compass.
|
||||
If you don't have a compass, you'll have to say R, L, A, or B, which
|
||||
stand for
|
||||
Right, Left, Ahead, and Back. Directions printed in room descriptions
|
||||
are
|
||||
always printed in R, L, A, & B relative directions.
|
||||
.SH HISTORY
|
||||
I wrote Battlestar in 1979 in order to experiment with the niceties of
|
||||
the C Language.
|
||||
Most interesting things that happen in the game are hardwired into the
|
||||
code, so don't
|
||||
send me any hate mail about it! Instead, enjoy art for art's sake!
|
||||
.SH AUTHOR
|
||||
David Riggle
|
||||
.SH "INSPIRATION & ASSISTANCE"
|
||||
Chris Guthrie
|
||||
.br
|
||||
Peter Da Silva
|
||||
.br
|
||||
Kevin Brown
|
||||
.br
|
||||
Edward Wang
|
||||
.br
|
||||
Ken Arnold & Company
|
||||
.SH BUGS
|
||||
Countless.
|
||||
.SH "FAN MAIL"
|
||||
Send to edward%ucbarpa@Berkeley.arpa, chris%ucbcory@berkeley.arpa,
|
||||
riggle.pa@xerox.arpa.
|
91
games/battlestar/battlestar.c
Normal file
91
games/battlestar/battlestar.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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[] = "@(#)battlestar.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* Battlestar - a stellar-tropical adventure game
|
||||
*
|
||||
* Originally written by His Lordship, Admiral David W. Horatio Riggle,
|
||||
* on the Cory PDP-11/70, University of California, Berkeley.
|
||||
*/
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
main(argc,argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
char mainbuf[LINELENGTH];
|
||||
char *next;
|
||||
|
||||
initialize(argc < 2 || strcmp(argv[1], "-r"));
|
||||
start:
|
||||
news();
|
||||
beenthere[position]++;
|
||||
if (notes[LAUNCHED])
|
||||
crash(); /* decrements fuel & crash */
|
||||
if (matchlight) {
|
||||
puts("Your match splutters out.");
|
||||
matchlight = 0;
|
||||
}
|
||||
if (!notes[CANTSEE] || testbit(inven,LAMPON) ||
|
||||
testbit(location[position].objects, LAMPON)) {
|
||||
writedes();
|
||||
printobjs();
|
||||
} else
|
||||
puts("It's too dark to see anything in here!");
|
||||
whichway(location[position]);
|
||||
run:
|
||||
next = getcom(mainbuf, sizeof mainbuf, ">-: ",
|
||||
"Please type in something.");
|
||||
for (wordcount = 0; next && wordcount < 20; wordcount++)
|
||||
next = getword(next, words[wordcount], -1);
|
||||
parse();
|
||||
switch (cypher()) {
|
||||
case -1:
|
||||
goto run;
|
||||
case 0:
|
||||
goto start;
|
||||
default:
|
||||
exit();
|
||||
}
|
||||
}
|
250
games/battlestar/com1.c
Normal file
250
games/battlestar/com1.c
Normal file
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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);
|
||||
time++;
|
||||
}
|
||||
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. */
|
||||
register struct objs *p;
|
||||
register 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 hurt;
|
||||
|
||||
if (time > 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 (time > 20 && position < 32)
|
||||
puts("Explosions rock the battlestar.");
|
||||
if (time > snooze){
|
||||
puts("You drop from exhaustion...");
|
||||
zzz();
|
||||
}
|
||||
if (time > snooze - 5)
|
||||
puts("You're getting tired.");
|
||||
if (time > (rythmn + CYCLE)) {
|
||||
if (location == nightfile) {
|
||||
convert(TODAY);
|
||||
if (OUTSIDE && time - 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 && time - 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 = time - time % 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 - time < 10){
|
||||
setbit(location[GARDEN].objects,GIRLTALK);
|
||||
setbit(location[GARDEN].objects,LAMPON);
|
||||
setbit(location[GARDEN].objects,ROPE);
|
||||
}
|
||||
if (position == DOCK && (beenthere[position] || time > CYCLE)){
|
||||
clearbit(location[DOCK].objects, GIRL);
|
||||
clearbit(location[DOCK].objects,MAN);
|
||||
}
|
||||
if (meetgirl && time - 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",clock);
|
||||
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);
|
||||
time += 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]);
|
||||
}
|
||||
}
|
296
games/battlestar/com2.c
Normal file
296
games/battlestar/com2.c
Normal file
@ -0,0 +1,296 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 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];
|
||||
time++;
|
||||
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.");
|
||||
time++;
|
||||
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;
|
||||
time++;
|
||||
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;
|
||||
|
||||
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])){
|
||||
time++;
|
||||
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 == time){
|
||||
puts("The Dark Lord leaps away and runs down secret tunnels and corridoors.");
|
||||
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 == time){
|
||||
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);
|
||||
}
|
312
games/battlestar/com3.c
Normal file
312
games/battlestar/com3.c
Normal file
@ -0,0 +1,312 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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");
|
||||
time++;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
time++;
|
||||
zzz();
|
||||
}
|
||||
else
|
||||
puts("I'm not thirsty.");
|
||||
}
|
||||
|
||||
shoot()
|
||||
{
|
||||
int firstnumber, value;
|
||||
register int n;
|
||||
|
||||
if (!testbit(inven,LASER))
|
||||
puts("You aren't holding a blaster.");
|
||||
else {
|
||||
firstnumber = wordnumber;
|
||||
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);
|
||||
time++;
|
||||
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){
|
||||
time++;
|
||||
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);
|
||||
}
|
379
games/battlestar/com4.c
Normal file
379
games/battlestar/com4.c
Normal file
@ -0,0 +1,379 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)com4.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
take(from)
|
||||
unsigned int from[];
|
||||
{
|
||||
int firstnumber, heavy, bulky, value;
|
||||
register 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];
|
||||
time++;
|
||||
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 = time;
|
||||
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)
|
||||
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)
|
||||
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;
|
||||
time++;
|
||||
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) && time > ate - CYCLE && testbit(inven,KNIFE)){
|
||||
clearbit(inven,value);
|
||||
carrying -= objwt[value];
|
||||
encumber -= objcumber[value];
|
||||
ate = max(time,ate) + CYCLE/3;
|
||||
snooze += CYCLE/10;
|
||||
time++;
|
||||
puts("Eaten. You can explore a little longer now.");
|
||||
}
|
||||
else if (time < 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);
|
||||
}
|
324
games/battlestar/com5.c
Normal file
324
games/battlestar/com5.c
Normal file
@ -0,0 +1,324 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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;
|
||||
|
||||
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;
|
||||
time += 10;
|
||||
zzz();
|
||||
}
|
||||
else {
|
||||
puts("You wish!");
|
||||
return;
|
||||
}
|
||||
if (wordvalue[wordnumber] == NATIVE){
|
||||
puts("The girl is easy prey. She peals off her sarong and indulges you.");
|
||||
power++;
|
||||
pleasure += 5;
|
||||
printf("Girl:\n");
|
||||
time += 10;
|
||||
zzz();
|
||||
}
|
||||
printf("Loved.\n");
|
||||
}
|
||||
else puts("I't doesn't seem to work.");
|
||||
}
|
||||
|
||||
zzz()
|
||||
{
|
||||
int oldtime;
|
||||
register int n;
|
||||
|
||||
oldtime = time;
|
||||
if ((snooze - time) < (0.75 * CYCLE)){
|
||||
time += 0.75 * CYCLE - (snooze - time);
|
||||
printf("<zzz>");
|
||||
for (n = 0; n < time - oldtime; n++)
|
||||
printf(".");
|
||||
printf("\n");
|
||||
snooze += 3 * (time - oldtime);
|
||||
if (notes[LAUNCHED]){
|
||||
fuel -= (time - 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 ((time / CYCLE + 1) % 2 && OUTSIDE)
|
||||
switch((time % 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((time % 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;
|
||||
}
|
||||
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.");
|
||||
return(0);
|
||||
}
|
||||
if (result != -1 && (testbit(location[position].objects,obj) || obj == AMULET || obj == MEDALION || obj == TALISMAN)){
|
||||
clearbit(location[position].objects,obj);
|
||||
time++;
|
||||
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 particulary");
|
||||
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 = time;
|
||||
}
|
||||
}
|
||||
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);
|
||||
return(firstnumber);
|
||||
}
|
213
games/battlestar/com6.c
Normal file
213
games/battlestar/com6.c
Normal file
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)com6.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
launch()
|
||||
{
|
||||
if (testbit(location[position].objects,VIPER) && !notes[CANTLAUNCH]){
|
||||
if (fuel > 4){
|
||||
clearbit(location[position].objects,VIPER);
|
||||
position = location[position].up;
|
||||
notes[LAUNCHED] = 1;
|
||||
time++;
|
||||
fuel -= 4;
|
||||
puts("You climb into the viper and prepare for launch.");
|
||||
puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
|
||||
return(1);
|
||||
}
|
||||
else
|
||||
puts("Not enough fuel to launch.");
|
||||
}
|
||||
else
|
||||
puts("Can't launch.");
|
||||
return(0);
|
||||
}
|
||||
|
||||
land()
|
||||
{
|
||||
if (notes[LAUNCHED] && testbit(location[position].objects,LAND) && location[position].down){
|
||||
notes[LAUNCHED] = 0;
|
||||
position = location[position].down;
|
||||
setbit(location[position].objects,VIPER);
|
||||
fuel -= 2;
|
||||
time++;
|
||||
puts("You are down.");
|
||||
return(1);
|
||||
}
|
||||
else
|
||||
puts("You can't land here.");
|
||||
return(0);
|
||||
}
|
||||
|
||||
die() /* endgame */
|
||||
{
|
||||
printf("bye.\nYour rating was %s.\n", rate());
|
||||
post(' ');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
live()
|
||||
{
|
||||
puts("\nYou win!");
|
||||
post('!');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* sigh -- this program thinks "time" is an int. It's easier to not load
|
||||
* <time.h> than try and fix it.
|
||||
*/
|
||||
#define KERNEL
|
||||
#include <sys/time.h>
|
||||
#undef KERNEL
|
||||
|
||||
post(ch)
|
||||
char ch;
|
||||
{
|
||||
FILE *fp;
|
||||
struct timeval tv;
|
||||
char *date, *ctime();
|
||||
int s = sigblock(sigmask(SIGINT));
|
||||
|
||||
gettimeofday(&tv, (struct timezone *)0); /* can't call time */
|
||||
date = ctime(&tv.tv_sec);
|
||||
date[24] = '\0';
|
||||
if (fp = fopen(_PATH_SCORE,"a")) {
|
||||
fprintf(fp, "%s %8s %c%20s", date, uname, ch, rate());
|
||||
if (wiz)
|
||||
fprintf(fp, " wizard\n");
|
||||
else if (tempwiz)
|
||||
fprintf(fp, " WIZARD!\n");
|
||||
else
|
||||
fprintf(fp, "\n");
|
||||
} else
|
||||
perror(_PATH_SCORE);
|
||||
sigsetmask(s);
|
||||
}
|
||||
|
||||
char *
|
||||
rate()
|
||||
{
|
||||
int score;
|
||||
|
||||
score = max(max(pleasure,power),ego);
|
||||
if (score == pleasure){
|
||||
if (score < 5)
|
||||
return("novice");
|
||||
else if (score < 20)
|
||||
return("junior voyeur");
|
||||
else if (score < 35)
|
||||
return("Don Juan");
|
||||
else return("Marquis De Sade");
|
||||
}
|
||||
else if (score == power){
|
||||
if (score < 5)
|
||||
return("serf");
|
||||
else if (score < 8)
|
||||
return("Samurai");
|
||||
else if (score < 13)
|
||||
return("Klingon");
|
||||
else if (score < 22)
|
||||
return("Darth Vader");
|
||||
else return("Sauron the Great");
|
||||
}
|
||||
else{
|
||||
if (score < 5)
|
||||
return("Polyanna");
|
||||
else if (score < 10)
|
||||
return("philanthropist");
|
||||
else if (score < 20)
|
||||
return("Tattoo");
|
||||
else return("Mr. Roarke");
|
||||
}
|
||||
}
|
||||
|
||||
drive()
|
||||
{
|
||||
if (testbit(location[position].objects,CAR)){
|
||||
puts("You hop in the car and turn the key. There is a perceptible grating noise,");
|
||||
puts("and an explosion knocks you unconscious...");
|
||||
clearbit(location[position].objects,CAR);
|
||||
setbit(location[position].objects,CRASH);
|
||||
injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
|
||||
time += 15;
|
||||
zzz();
|
||||
return(0);
|
||||
}
|
||||
else
|
||||
puts("There is nothing to drive here.");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
ride()
|
||||
{
|
||||
if (testbit(location[position].objects,HORSE)){
|
||||
puts("You climb onto the stallion and kick it in the guts. The stupid steed launches");
|
||||
puts("forward through bush and fern. You are thrown and the horse gallups off.");
|
||||
clearbit(location[position].objects,HORSE);
|
||||
while (!(position = rnd(NUMOFROOMS+1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere);
|
||||
setbit(location[position].objects,HORSE);
|
||||
if (location[position].north)
|
||||
position = location[position].north;
|
||||
else if (location[position].south)
|
||||
position = location[position].south;
|
||||
else if (location[position].east)
|
||||
position = location[position].east;
|
||||
else
|
||||
position = location[position].west;
|
||||
return(0);
|
||||
}
|
||||
else puts("There is no horse here.");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
light() /* synonyms = {strike, smoke} */
|
||||
{ /* for matches, cigars */
|
||||
if (testbit(inven,MATCHES) && matchcount){
|
||||
puts("Your match splutters to life.");
|
||||
time++;
|
||||
matchlight = 1;
|
||||
matchcount--;
|
||||
if (position == 217){
|
||||
puts("The whole bungalow explodes with an intense blast.");
|
||||
die();
|
||||
}
|
||||
}
|
||||
else puts("You're out of matches.");
|
||||
}
|
268
games/battlestar/com7.c
Normal file
268
games/battlestar/com7.c
Normal file
@ -0,0 +1,268 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)com7.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
fight(enemy,strength)
|
||||
int enemy,strength;
|
||||
{
|
||||
int lifeline = 0;
|
||||
int hurt;
|
||||
char auxbuf[LINELENGTH];
|
||||
char *next;
|
||||
int i;
|
||||
int exhaustion;
|
||||
|
||||
fighton:
|
||||
time++;
|
||||
snooze -= 5;
|
||||
if (snooze > time)
|
||||
exhaustion = CYCLE/(snooze - time);
|
||||
else {
|
||||
puts("You collapse exhausted, and he pulverizes your skull.");
|
||||
die();
|
||||
}
|
||||
if (snooze - time < 20)
|
||||
puts("You look tired! I hope you're able to fight.");
|
||||
next = getcom(auxbuf, LINELENGTH, "<fight!>-: ", 0);
|
||||
for (i=0; next && i < 10; i++)
|
||||
next = getword(next, words[i], -1);
|
||||
parse();
|
||||
switch(wordvalue[wordnumber]){
|
||||
|
||||
case KILL:
|
||||
case SMITE:
|
||||
if (testbit(inven,TWO_HANDED))
|
||||
hurt = rnd(70) - 2 * card(injuries,NUMOFINJURIES) - ucard(wear) - exhaustion;
|
||||
else if (testbit(inven,SWORD) || testbit(inven, BROAD))
|
||||
hurt = rnd(50)%(WEIGHT-carrying)-card(injuries,NUMOFINJURIES)-encumber - exhaustion;
|
||||
else if (testbit(inven,KNIFE) || testbit(inven,MALLET) || testbit(inven,CHAIN) || testbit(inven,MACE) || testbit(inven,HALBERD))
|
||||
hurt = rnd(15) - card(injuries,NUMOFINJURIES) - exhaustion;
|
||||
else
|
||||
hurt = rnd(7) - encumber;
|
||||
if (hurt < 5)
|
||||
switch(rnd(3)){
|
||||
|
||||
case 0:
|
||||
puts("You swung wide and missed.");
|
||||
break;
|
||||
case 1:
|
||||
puts("He checked your blow. CLASH! CLANG!");
|
||||
break;
|
||||
case 2:
|
||||
puts("His filthy tunic hangs by one less thread.");
|
||||
break;
|
||||
}
|
||||
else if (hurt < 10){
|
||||
switch(rnd(3)){
|
||||
case 0:
|
||||
puts("He's bleeding.");
|
||||
break;
|
||||
case 1:
|
||||
puts("A trickle of blood runs down his face.");
|
||||
break;
|
||||
case 2:
|
||||
puts("A huge purple bruise is forming on the side of his face.");
|
||||
break;
|
||||
}
|
||||
lifeline++;
|
||||
}
|
||||
else if (hurt < 20){
|
||||
switch(rnd(3)){
|
||||
case 0:
|
||||
puts("He staggers back quavering.");
|
||||
break;
|
||||
case 1:
|
||||
puts("He jumps back with his hand over the wound.");
|
||||
break;
|
||||
case 2:
|
||||
puts("His shirt falls open with a swath across the chest.");
|
||||
break;
|
||||
}
|
||||
lifeline += 5;
|
||||
}
|
||||
else if (hurt < 30){
|
||||
switch(rnd(3)){
|
||||
case 0:
|
||||
printf("A bloody gash opens up on his %s side.\n",(rnd(2) ? "left" : "right"));
|
||||
break;
|
||||
case 1:
|
||||
puts("The steel bites home and scrapes along his ribs.");
|
||||
break;
|
||||
case 2:
|
||||
puts("You pierce him, and his breath hisses through clenched teeth.");
|
||||
break;
|
||||
}
|
||||
lifeline += 10;
|
||||
}
|
||||
else if (hurt < 40){
|
||||
switch(rnd(3)){
|
||||
case 0:
|
||||
puts("You smite him to the ground.");
|
||||
if (strength - lifeline > 20)
|
||||
puts("But in a flurry of steel he regains his feet!");
|
||||
break;
|
||||
case 1:
|
||||
puts("The force of your blow sends him to his knees.");
|
||||
puts("His arm swings lifeless at his side.");
|
||||
break;
|
||||
case 2:
|
||||
puts("Clutching his blood drenched shirt, he collapses stunned.");
|
||||
break;
|
||||
}
|
||||
lifeline += 20;
|
||||
}
|
||||
else {
|
||||
switch(rnd(3)){
|
||||
case 0:
|
||||
puts("His ribs crack under your powerful swing, flooding his lungs with blood.");
|
||||
break;
|
||||
case 1:
|
||||
puts("You shatter his upheld arm in a spray of blood. The blade continues deep");
|
||||
puts("into his back, severing the spinal cord.");
|
||||
lifeline += 25;
|
||||
break;
|
||||
case 2:
|
||||
puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground.");
|
||||
lifeline += 25;
|
||||
break;
|
||||
}
|
||||
lifeline += 30;
|
||||
}
|
||||
break;
|
||||
|
||||
case BACK:
|
||||
if (enemy == DARK && lifeline > strength * 0.33){
|
||||
puts("He throws you back against the rock and pummels your face.");
|
||||
if (testbit(inven,AMULET) || testbit(wear,AMULET)){
|
||||
printf("Lifting the amulet from you, ");
|
||||
if (testbit(inven,MEDALION) || testbit(wear,MEDALION)){
|
||||
puts("his power grows and the walls of\nthe earth tremble.");
|
||||
puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse.");
|
||||
puts("The planet is consumed by darkness.");
|
||||
die();
|
||||
}
|
||||
if (testbit(inven,AMULET)){
|
||||
clearbit(inven,AMULET);
|
||||
carrying -= objwt[AMULET];
|
||||
encumber -= objcumber[AMULET];
|
||||
}
|
||||
else
|
||||
clearbit(wear,AMULET);
|
||||
puts("he flees down the dark caverns.");
|
||||
clearbit(location[position].objects,DARK);
|
||||
injuries[SKULL] = 1;
|
||||
followfight = time;
|
||||
return (0);
|
||||
}
|
||||
else{
|
||||
puts("I'm afraid you have been killed.");
|
||||
die();
|
||||
}
|
||||
}
|
||||
else{
|
||||
puts("You escape stunned and disoriented from the fight.");
|
||||
puts("A victorious bellow echoes from the battlescene.");
|
||||
if (back && position != back)
|
||||
move(back,BACK);
|
||||
else if (ahead &&position != ahead)
|
||||
move(ahead,AHEAD);
|
||||
else if (left && position != left)
|
||||
move(left,LEFT);
|
||||
else if (right && position != right)
|
||||
move(right,RIGHT);
|
||||
else
|
||||
move(location[position].down,AHEAD);
|
||||
return(0);
|
||||
}
|
||||
|
||||
case SHOOT:
|
||||
if (testbit(inven,LASER)){
|
||||
if (strength - lifeline <= 50){
|
||||
printf("The %s took a direct hit!\n",objsht[enemy]);
|
||||
lifeline += 50;
|
||||
}
|
||||
else {
|
||||
puts("With his bare hand he deflects the laser blast and whips the pistol from you!");
|
||||
clearbit(inven,LASER);
|
||||
setbit(location[position].objects,LASER);
|
||||
carrying -= objwt[LASER];
|
||||
encumber -= objcumber[LASER];
|
||||
}
|
||||
}
|
||||
else
|
||||
puts("Unfortunately, you don't have a blaster handy.");
|
||||
break;
|
||||
|
||||
case DROP:
|
||||
case DRAW:
|
||||
cypher();
|
||||
time--;
|
||||
break;
|
||||
|
||||
default:
|
||||
puts("You don't have a chance, he is too quick.");
|
||||
break;
|
||||
|
||||
}
|
||||
if (lifeline >= strength){
|
||||
printf("You have killed the %s.\n", objsht[enemy]);
|
||||
if (enemy == ELF || enemy == DARK)
|
||||
puts("A watery black smoke consumes his body and then vanishes with a peal of thunder!");
|
||||
clearbit(location[position].objects,enemy);
|
||||
power += 2;
|
||||
notes[JINXED]++;
|
||||
return(0);
|
||||
}
|
||||
puts("He attacks...");
|
||||
/* some embellisments */
|
||||
hurt = rnd(NUMOFINJURIES) - (testbit(inven,SHIELD) != 0) - (testbit(wear,MAIL) != 0) - (testbit(wear,HELM) != 0);
|
||||
hurt += (testbit(wear,AMULET) != 0) + (testbit(wear,MEDALION) != 0) + (testbit(wear,TALISMAN) != 0);
|
||||
hurt = hurt < 0 ? 0 : hurt;
|
||||
hurt = hurt >= NUMOFINJURIES ? NUMOFINJURIES -1 : hurt;
|
||||
if (!injuries[hurt]){
|
||||
injuries[hurt] = 1;
|
||||
printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
|
||||
}
|
||||
else
|
||||
puts("You emerge unscathed.");
|
||||
if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){
|
||||
puts("I'm afraid you have suffered fatal injuries.");
|
||||
die();
|
||||
}
|
||||
goto fighton;
|
||||
}
|
430
games/battlestar/cypher.c
Normal file
430
games/battlestar/cypher.c
Normal file
@ -0,0 +1,430 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)cypher.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
cypher()
|
||||
{
|
||||
register 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) = ",time);
|
||||
fgets(buffer,10,stdin);
|
||||
if (*buffer != '\n')
|
||||
sscanf(buffer,"%d", &time);
|
||||
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) = ",clock);
|
||||
fgets(buffer,10,stdin);
|
||||
if (*buffer != '\n')
|
||||
sscanf(buffer,"%d",&clock);
|
||||
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(),time);
|
||||
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);
|
||||
}
|
1205
games/battlestar/dayfile.c
Normal file
1205
games/battlestar/dayfile.c
Normal file
File diff suppressed because it is too large
Load Diff
138
games/battlestar/dayobjs.c
Normal file
138
games/battlestar/dayobjs.c
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)dayobjs.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
struct objs dayobjs[] = {
|
||||
{ 236, HORSE },
|
||||
{ 237, CAR },
|
||||
{ 275, POT },
|
||||
{ 275, BAR },
|
||||
{ 275, BLOCK },
|
||||
{ 260, COINS },
|
||||
{ 266, DARK },
|
||||
{ 235, TIMER },
|
||||
{ 51, 51 },
|
||||
{ 59, 51 },
|
||||
{ 48, 51 },
|
||||
{ 66, 52 },
|
||||
{ 65, 52 },
|
||||
{ 19, BOMB },
|
||||
{ 167, NATIVE },
|
||||
{ 21, KNIFE },
|
||||
{ 30, KNIFE },
|
||||
{ 30, CLEAVER },
|
||||
{ 260, SWORD },
|
||||
{ 70, LAND },
|
||||
{ 71, LAND },
|
||||
{ 72, LAND },
|
||||
{ 73, LAND },
|
||||
{ 74, LAND },
|
||||
{ 75, LAND },
|
||||
{ 76, LAND },
|
||||
{ 77, LAND },
|
||||
{ 78, LAND },
|
||||
{ 79, LAND },
|
||||
{ 81, LAND },
|
||||
{ 82, LAND },
|
||||
{ 83, LAND },
|
||||
{ 84, LAND },
|
||||
{ 85, LAND },
|
||||
{ 86, LAND },
|
||||
{ 87, LAND },
|
||||
{ 88, LAND },
|
||||
{ 90, LAND },
|
||||
{ 95, LAND },
|
||||
{ 96, LAND },
|
||||
{ 97, LAND },
|
||||
{ 99, LAND },
|
||||
{ 100, LAND },
|
||||
{ 104, LAND },
|
||||
{ 172, WOODSMAN },
|
||||
{ 172, DEADWOOD },
|
||||
{ 172, MALLET },
|
||||
{ 146, ELF },
|
||||
{ 146, HALBERD },
|
||||
{ 146, SHIELD },
|
||||
{ 190, TWO_HANDED },
|
||||
{ 190, POTION },
|
||||
{ 142, BROAD },
|
||||
{ 258, MAIL },
|
||||
{ 258, HELM },
|
||||
{ 21, MAID },
|
||||
{ 7, VIPER },
|
||||
{ 216, SHOES },
|
||||
{ 64, CYLON },
|
||||
{ 36, CYLON },
|
||||
{ 49, CYLON },
|
||||
{ 8, ROBE },
|
||||
{ 13, AMULET },
|
||||
{ 20, LASER },
|
||||
{ 126, BATHGOD },
|
||||
{ 26, GRENADE },
|
||||
{ 256, GRENADE },
|
||||
{ 237, CHAIN },
|
||||
{ 237, COMPASS },
|
||||
{ 218, LEVIS },
|
||||
{ 164, MACE },
|
||||
{ 137, SHOVEL },
|
||||
{ 11, COINS },
|
||||
{ 24, MATCHES },
|
||||
{ 235, MATCHES },
|
||||
{ 93, MAN },
|
||||
{ 109, PAPAYAS },
|
||||
{ 110, PINEAPPLE },
|
||||
{ 152, PINEAPPLE },
|
||||
{ 154, PINEAPPLE },
|
||||
{ 111, KIWI },
|
||||
{ 149, MANGO },
|
||||
{ 112, COCONUTS },
|
||||
{ 150, COCONUTS },
|
||||
{ 151, COCONUTS },
|
||||
{ 153, COCONUTS },
|
||||
{ 192, COCONUTS },
|
||||
{ 204, COCONUTS },
|
||||
{ 207, COCONUTS },
|
||||
{ 209, COCONUTS },
|
||||
{ 213, COCONUTS },
|
||||
{ 240, COCONUTS },
|
||||
{ 218, RING },
|
||||
{ 130, BRACELET },
|
||||
{ 93, GIRL },
|
||||
{ 268, LAMPON },
|
||||
0
|
||||
};
|
297
games/battlestar/externs.h
Normal file
297
games/battlestar/externs.h
Normal file
@ -0,0 +1,297 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* @(#)externs.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
#include <sys/signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define BITS (8 * sizeof (int))
|
||||
|
||||
#define OUTSIDE (position > 68 && position < 246 && position != 218)
|
||||
#define rnd(x) (rand() % (x))
|
||||
#define max(a,b) ((a) < (b) ? (b) : (a))
|
||||
#define testbit(array, index) (array[index/BITS] & (1 << (index % BITS)))
|
||||
#define setbit(array, index) (array[index/BITS] |= (1 << (index % BITS)))
|
||||
#define clearbit(array, index) (array[index/BITS] &= ~(1 << (index % BITS)))
|
||||
|
||||
/* well known rooms */
|
||||
#define FINAL 275
|
||||
#define GARDEN 197
|
||||
#define POOLS 126
|
||||
#define DOCK 93
|
||||
|
||||
/* word types */
|
||||
#define VERB 0
|
||||
#define OBJECT 1
|
||||
#define NOUNS 2
|
||||
#define PREPS 3
|
||||
#define ADJS 4
|
||||
#define CONJ 5
|
||||
|
||||
/* words numbers */
|
||||
#define KNIFE 0
|
||||
#define SWORD 1
|
||||
#define LAND 2
|
||||
#define WOODSMAN 3
|
||||
#define TWO_HANDED 4
|
||||
#define CLEAVER 5
|
||||
#define BROAD 6
|
||||
#define MAIL 7
|
||||
#define HELM 8
|
||||
#define SHIELD 9
|
||||
#define MAID 10
|
||||
#define BODY 10
|
||||
#define VIPER 11
|
||||
#define LAMPON 12
|
||||
#define SHOES 13
|
||||
#define CYLON 14
|
||||
#define PAJAMAS 15
|
||||
#define ROBE 16
|
||||
#define AMULET 17
|
||||
#define MEDALION 18
|
||||
#define TALISMAN 19
|
||||
#define DEADWOOD 20
|
||||
#define MALLET 21
|
||||
#define LASER 22
|
||||
#define BATHGOD 23
|
||||
#define NORMGOD 24
|
||||
#define GRENADE 25
|
||||
#define CHAIN 26
|
||||
#define ROPE 27
|
||||
#define LEVIS 28
|
||||
#define MACE 29
|
||||
#define SHOVEL 30
|
||||
#define HALBERD 31
|
||||
#define COMPASS 32
|
||||
#define CRASH 33
|
||||
#define ELF 34
|
||||
#define FOOT 35
|
||||
#define COINS 36
|
||||
#define MATCHES 37
|
||||
#define MAN 38
|
||||
#define PAPAYAS 39
|
||||
#define PINEAPPLE 40
|
||||
#define KIWI 41
|
||||
#define COCONUTS 42
|
||||
#define MANGO 43
|
||||
#define RING 44
|
||||
#define POTION 45
|
||||
#define BRACELET 46
|
||||
#define GIRL 47
|
||||
#define GIRLTALK 48
|
||||
#define DARK 49
|
||||
#define TIMER 50
|
||||
#define CHAR 53
|
||||
#define BOMB 54
|
||||
#define DEADGOD 55
|
||||
#define DEADTIME 56
|
||||
#define DEADNATIVE 57
|
||||
#define NATIVE 58
|
||||
#define HORSE 59
|
||||
#define CAR 60
|
||||
#define POT 61
|
||||
#define BAR 62
|
||||
#define BLOCK 63
|
||||
#define NUMOFOBJECTS 64
|
||||
/* non-objects below */
|
||||
#define UP 1000
|
||||
#define DOWN 1001
|
||||
#define AHEAD 1002
|
||||
#define BACK 1003
|
||||
#define RIGHT 1004
|
||||
#define LEFT 1005
|
||||
#define TAKE 1006
|
||||
#define USE 1007
|
||||
#define LOOK 1008
|
||||
#define QUIT 1009
|
||||
#define NORTH 1010
|
||||
#define SOUTH 1011
|
||||
#define EAST 1012
|
||||
#define WEST 1013
|
||||
#define SU 1014
|
||||
#define DROP 1015
|
||||
#define TAKEOFF 1016
|
||||
#define DRAW 1017
|
||||
#define PUTON 1018
|
||||
#define WEARIT 1019
|
||||
#define PUT 1020
|
||||
#define INVEN 1021
|
||||
#define EVERYTHING 1022
|
||||
#define AND 1023
|
||||
#define KILL 1024
|
||||
#define RAVAGE 1025
|
||||
#define UNDRESS 1026
|
||||
#define THROW 1027
|
||||
#define LAUNCH 1028
|
||||
#define LANDIT 1029
|
||||
#define LIGHT 1030
|
||||
#define FOLLOW 1031
|
||||
#define KISS 1032
|
||||
#define LOVE 1033
|
||||
#define GIVE 1034
|
||||
#define SMITE 1035
|
||||
#define SHOOT 1036
|
||||
#define ON 1037
|
||||
#define OFF 1038
|
||||
#define TIME 1039
|
||||
#define SLEEP 1040
|
||||
#define DIG 1041
|
||||
#define EAT 1042
|
||||
#define SWIM 1043
|
||||
#define DRINK 1044
|
||||
#define DOOR 1045
|
||||
#define SAVE 1046
|
||||
#define RIDE 1047
|
||||
#define DRIVE 1048
|
||||
#define SCORE 1049
|
||||
#define BURY 1050
|
||||
#define JUMP 1051
|
||||
#define KICK 1052
|
||||
|
||||
/* injuries */
|
||||
#define ARM 6 /* broken arm */
|
||||
#define RIBS 7 /* broken ribs */
|
||||
#define SPINE 9 /* broken back */
|
||||
#define SKULL 11 /* fractured skull */
|
||||
#define INCISE 10 /* deep incisions */
|
||||
#define NECK 12 /* broken NECK */
|
||||
#define NUMOFINJURIES 13
|
||||
|
||||
/* notes */
|
||||
#define CANTLAUNCH 0
|
||||
#define LAUNCHED 1
|
||||
#define CANTSEE 2
|
||||
#define CANTMOVE 3
|
||||
#define JINXED 4
|
||||
#define DUG 5
|
||||
#define NUMOFNOTES 6
|
||||
|
||||
/* fundamental constants */
|
||||
#define NUMOFROOMS 275
|
||||
#define NUMOFWORDS ((NUMOFOBJECTS + BITS - 1) / BITS)
|
||||
#define LINELENGTH 81
|
||||
|
||||
#define TODAY 0
|
||||
#define TONIGHT 1
|
||||
#define CYCLE 100
|
||||
|
||||
/* initial variable values */
|
||||
#define TANKFULL 250
|
||||
#define TORPEDOES 10
|
||||
#define MAXWEIGHT 60
|
||||
#define MAXCUMBER 10
|
||||
|
||||
struct room {
|
||||
char *name;
|
||||
int link[8];
|
||||
#define north link[0]
|
||||
#define south link[1]
|
||||
#define east link[2]
|
||||
#define west link[3]
|
||||
#define up link[4]
|
||||
#define access link[5]
|
||||
#define down link[6]
|
||||
#define flyhere link[7]
|
||||
char *desc;
|
||||
unsigned int objects[NUMOFWORDS];
|
||||
};
|
||||
struct room dayfile[];
|
||||
struct room nightfile[];
|
||||
struct room *location;
|
||||
|
||||
/* object characteristics */
|
||||
char *objdes[NUMOFOBJECTS];
|
||||
char *objsht[NUMOFOBJECTS];
|
||||
char *ouch[NUMOFINJURIES];
|
||||
int objwt[NUMOFOBJECTS];
|
||||
int objcumber[NUMOFOBJECTS];
|
||||
|
||||
/* current input line */
|
||||
#define NWORD 20 /* words per line */
|
||||
char words[NWORD][15];
|
||||
int wordvalue[NWORD];
|
||||
int wordtype[NWORD];
|
||||
int wordcount, wordnumber;
|
||||
|
||||
char *truedirec(), *rate();
|
||||
char *getcom(), *getword();
|
||||
|
||||
/* state of the game */
|
||||
int time;
|
||||
int position;
|
||||
int direction;
|
||||
int left, right, ahead, back;
|
||||
int clock, fuel, torps;
|
||||
int carrying, encumber;
|
||||
int rythmn;
|
||||
int followfight;
|
||||
int ate;
|
||||
int snooze;
|
||||
int meetgirl;
|
||||
int followgod;
|
||||
int godready;
|
||||
int win;
|
||||
int wintime;
|
||||
int wiz;
|
||||
int tempwiz;
|
||||
int matchlight, matchcount;
|
||||
int loved;
|
||||
int pleasure, power, ego;
|
||||
int WEIGHT;
|
||||
int CUMBER;
|
||||
int notes[NUMOFNOTES];
|
||||
unsigned int inven[NUMOFWORDS];
|
||||
unsigned int wear[NUMOFWORDS];
|
||||
char beenthere[NUMOFROOMS+1];
|
||||
char injuries[NUMOFINJURIES];
|
||||
|
||||
char uname[9];
|
||||
|
||||
struct wlist {
|
||||
char *string;
|
||||
int value, article;
|
||||
struct wlist *next;
|
||||
};
|
||||
#define HASHSIZE 256
|
||||
#define HASHMUL 81
|
||||
#define HASHMASK (HASHSIZE - 1)
|
||||
struct wlist *hashtab[HASHSIZE];
|
||||
struct wlist wlist[];
|
||||
|
||||
struct objs {
|
||||
short room;
|
||||
short obj;
|
||||
};
|
||||
struct objs dayobjs[];
|
||||
struct objs nightobjs[];
|
283
games/battlestar/fly.c
Normal file
283
games/battlestar/fly.c
Normal file
@ -0,0 +1,283 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)fly.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
#undef UP
|
||||
#include <curses.h>
|
||||
|
||||
#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 clock = 120; /* time 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 (clock <= 0){
|
||||
endfly();
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
screen()
|
||||
{
|
||||
register 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;
|
||||
|
||||
move(MIDR,MIDC-10);
|
||||
addstr("------- + -------");
|
||||
for (n = MIDR-4; n < MIDR-1; n++){
|
||||
mvaddch(n,MIDC,'|');
|
||||
mvaddch(n+6,MIDC,'|');
|
||||
}
|
||||
}
|
||||
|
||||
notarget()
|
||||
{
|
||||
register 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;
|
||||
|
||||
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));
|
||||
}
|
||||
clock--;
|
||||
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", clock);
|
||||
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);
|
||||
}
|
99
games/battlestar/getcom.c
Normal file
99
games/battlestar/getcom.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)getcom.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char *
|
||||
getcom(buf, size, prompt, error)
|
||||
char *buf;
|
||||
int size;
|
||||
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;
|
||||
{
|
||||
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);
|
||||
}
|
219
games/battlestar/globals.c
Normal file
219
games/battlestar/globals.c
Normal file
@ -0,0 +1,219 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)globals.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
int WEIGHT = MAXWEIGHT;
|
||||
int CUMBER = MAXCUMBER;
|
||||
|
||||
char *objdes[NUMOFOBJECTS] = {
|
||||
"There is a knife here",
|
||||
"There is an exquisitely crafted sword and scabbard here.",
|
||||
0, /* can land from here */
|
||||
"There is a fierce woodsman here brandishing a heavy mallet.",
|
||||
"There is an unweildly two-handed sword here.",
|
||||
"There is a bloody meat cleaver here.",
|
||||
"A rusty broadsword is lying here.",
|
||||
"There is an ancient coat of finely woven mail here.",
|
||||
"There is a old dented helmet with an ostrich plume here.",
|
||||
"There is a shield of some native tribe here.",
|
||||
"The maid's body is lying here. She was murdered!",
|
||||
"There is a Viper ready for launch here.",
|
||||
"A kerosene lantern is burning luridly here.",
|
||||
"An old pair of shoes has been discarded here.",
|
||||
0, /* cylon */
|
||||
"There is a pair of pajamas here.",
|
||||
"A kingly robe of royal purple and spun gold is draped here.",
|
||||
"There is a strange golden amulet on the floor here.",
|
||||
"A medallion of solid gold shimmers on the ground nearby.",
|
||||
"A talisman of gold is lying here.",
|
||||
"A dead woodsman has fallen here. He was savagely murdered.",
|
||||
"A heavy wooden mallet lies nearby.",
|
||||
"There is a laser pistol here.",
|
||||
"A flower-like young goddess is bathing in the hot mineral pools. She is \nwatching you, but continues to steep and sing softly.",
|
||||
"The goddess is reclining on a bed of ferns and studying you intently.",
|
||||
"There is a grenade here",
|
||||
"There is a length of heavy chain here.",
|
||||
"There is a stout rope here.",
|
||||
"There is a pair of Levi's here.",
|
||||
"A bloody mace is lying on the ground here.",
|
||||
"There is a shovel here.",
|
||||
"A long, sharp halberd is propped up here.",
|
||||
"There is a compass here",
|
||||
"Wreckage and smoldering debris from a crash litter the ground here.",
|
||||
"A woodland Elf armed with a shield and deadly halberd lunges toward you!",
|
||||
"I think I hear footsteps behind us.",
|
||||
"There are a few coins here.",
|
||||
"There are some matches here.",
|
||||
"An unctuous man in a white suit and a dwarf are standing here.",
|
||||
"There are some ripe papayas here.",
|
||||
"There is a ripe pineapple here.",
|
||||
"There are some kiwi fruit here.",
|
||||
"There are some coconuts here.",
|
||||
"There is a ripe mango here.",
|
||||
"There is a sparkling diamond ring here.",
|
||||
"There is a colorful pink potion in a small crystal vial here.",
|
||||
"A gold bracelet is on the ground here.",
|
||||
"A swarthy woman with stern features pulls you aside from the crowd,\n'I must talk to you -- but not here. Meet me at midnight in the gardens.'",
|
||||
"The swarthy woman has been awaiting you anxiousy. 'I must warn you that the\nIsland has anticipated your Quest. You will not be welcomed. The Darkness is\nstrong where you must search. Seek not the shadows save only at night, for\nthen are they the weakest. In the mountains far from here a canyon winds\nwith ferns and streams and forgotten vines. There you must go. Take this\nrope.'",
|
||||
"Out from the shadows a figure leaps! His black cape swirls around, and he\nholds a laser sword at your chest. 'So, you have come to fulfill the Quest.\nHa! Your weapons are no match for me!'",
|
||||
"An old timer with one eye missing and no money for a drink sits at the bar.",
|
||||
"You are flying through an asteroid field!",
|
||||
"A planet is nearby.",
|
||||
"The ground is charred here.",
|
||||
"There is a thermonuclear warhead here.",
|
||||
"The fragile, beautiful young goddess lies here. You murdered her horribly.",
|
||||
"The old timer is lying here. He is dead.",
|
||||
"The native girl's body is lying here.",
|
||||
"A native girl is sitting here.",
|
||||
"A gorgeous white stallion is standing here.",
|
||||
"The keys are in the ignition.",
|
||||
"A pot of pearls and jewels is sitting here.",
|
||||
"A bar of solid gold is here.",
|
||||
"There is a 10 kilogram diamond block here."
|
||||
|
||||
};
|
||||
|
||||
char *objsht[NUMOFOBJECTS] = {
|
||||
"knife",
|
||||
"fine sword",
|
||||
0,
|
||||
"Woodsman",
|
||||
"two-handed sword",
|
||||
"meat cleaver",
|
||||
"broadsword",
|
||||
"coat of mail",
|
||||
"plumed helmet",
|
||||
"shield",
|
||||
"maid's body",
|
||||
"viper",
|
||||
"lantern",
|
||||
"shoes",
|
||||
0,
|
||||
"pajamas",
|
||||
"robe",
|
||||
"amulet",
|
||||
"medallion",
|
||||
"talisman",
|
||||
"woodsman's body",
|
||||
"wooden mallet",
|
||||
"laser",
|
||||
0,
|
||||
0,
|
||||
"grenade",
|
||||
"chain",
|
||||
"rope",
|
||||
"levis",
|
||||
"mace",
|
||||
"shovel",
|
||||
"halberd",
|
||||
"compass",
|
||||
0,
|
||||
"Elf",
|
||||
0,
|
||||
"coins",
|
||||
"match book",
|
||||
0,
|
||||
"papayas",
|
||||
"pineapple",
|
||||
"kiwi",
|
||||
"coconuts",
|
||||
"mango",
|
||||
"ring",
|
||||
"potion",
|
||||
"bracelet",
|
||||
0,
|
||||
0,
|
||||
"Dark Lord",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"warhead",
|
||||
"goddess's body",
|
||||
"old timer's body",
|
||||
"girl's body",
|
||||
0,
|
||||
"stallion",
|
||||
"car",
|
||||
"pot of jewels",
|
||||
"bar of gold",
|
||||
"diamond block"
|
||||
};
|
||||
|
||||
char *ouch[NUMOFINJURIES] = {
|
||||
"some minor abrasions",
|
||||
"some minor lacerations",
|
||||
"a minor puncture wound",
|
||||
"a minor amputation",
|
||||
"a sprained wrist",
|
||||
"a fractured ankle and shattered kneecap",
|
||||
"a broken arm and dislocated shoulder",
|
||||
"a few broken ribs",
|
||||
"a broken leg and torn ligaments",
|
||||
"a broken back and ruptured spleen",
|
||||
"some deep incisions and a loss of blood",
|
||||
"a fractured skull and mashed face",
|
||||
"a broken neck"
|
||||
};
|
||||
|
||||
int objwt[NUMOFOBJECTS] = {
|
||||
1, 5, 0, 10, 15, 2, 10, 10,
|
||||
3, 5, 50, 2500, 2, 1, 100, 1,
|
||||
2, 1, 1, 1, 60, 10, 5, 0,
|
||||
50, 5, 15, 5, 1, 20, 10, 10,
|
||||
0, 0, 0, 0, 1, 0, 0, 1,
|
||||
1, 1, 2, 1, 0, 0, 0, 0,
|
||||
0, 0, 100, 0, 0, 0, 55, 47,
|
||||
50, 45, 45, 100, 2000, 30, 20, 10
|
||||
};
|
||||
|
||||
int objcumber[NUMOFOBJECTS] = {
|
||||
1, 5, 0, 150, 10, 1, 5, 2,
|
||||
2, 1, 5, 10, 1, 1, 10, 1,
|
||||
1, 1, 1, 1, 7, 5, 4, 0,
|
||||
0, 1, 1, 1, 1, 5, 4, 4,
|
||||
1, 0, 0, 0, 1, 0, 0, 1,
|
||||
1, 1, 3, 1, 0, 0, 1, 0,
|
||||
0, 0, 10, 0, 0, 0, 7, 8,
|
||||
10, 8, 8, 10, 10, 3, 1, 2
|
||||
};
|
||||
|
||||
int win = 1;
|
||||
int matchcount = 20;
|
||||
int followgod = -1;
|
||||
int followfight = -1;
|
130
games/battlestar/init.c
Normal file
130
games/battlestar/init.c
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "externs.h"
|
||||
#include <pwd.h>
|
||||
|
||||
initialize(startup)
|
||||
char startup;
|
||||
{
|
||||
register struct objs *p;
|
||||
void die();
|
||||
|
||||
puts("Version 4.2, fall 1984.");
|
||||
puts("First Adventure game written by His Lordship, the honorable");
|
||||
puts("Admiral D.W. Riggle\n");
|
||||
srand(getpid());
|
||||
getutmp(uname);
|
||||
wiz = wizard(uname);
|
||||
wordinit();
|
||||
if (startup) {
|
||||
location = dayfile;
|
||||
direction = NORTH;
|
||||
time = 0;
|
||||
snooze = CYCLE * 1.5;
|
||||
position = 22;
|
||||
setbit(wear, PAJAMAS);
|
||||
fuel = TANKFULL;
|
||||
torps = TORPEDOES;
|
||||
for (p = dayobjs; p->room != 0; p++)
|
||||
setbit(location[p->room].objects, p->obj);
|
||||
} else
|
||||
restore();
|
||||
signal(SIGINT, die);
|
||||
}
|
||||
|
||||
getutmp(uname)
|
||||
char *uname;
|
||||
{
|
||||
struct passwd *ptr;
|
||||
|
||||
ptr = getpwuid(getuid());
|
||||
strcpy(uname, ptr ? ptr->pw_name : "");
|
||||
}
|
||||
|
||||
char *list[] = { /* hereditary wizards */
|
||||
"riggle",
|
||||
"chris",
|
||||
"edward",
|
||||
"comay",
|
||||
"yee",
|
||||
"dmr",
|
||||
"ken",
|
||||
0
|
||||
};
|
||||
|
||||
char *badguys[] = {
|
||||
"wnj",
|
||||
"root",
|
||||
"ted",
|
||||
0
|
||||
};
|
||||
|
||||
wizard(uname)
|
||||
char *uname;
|
||||
{
|
||||
char flag;
|
||||
|
||||
if (flag = checkout(uname))
|
||||
printf("You are the Great wizard %s.\n", uname);
|
||||
return flag;
|
||||
}
|
||||
|
||||
checkout(uname)
|
||||
register char *uname;
|
||||
{
|
||||
register char **ptr;
|
||||
|
||||
for (ptr = list; *ptr; ptr++)
|
||||
if (strcmp(*ptr, uname) == 0)
|
||||
return 1;
|
||||
for (ptr = badguys; *ptr; ptr++)
|
||||
if (strcmp(*ptr, uname) == 0) {
|
||||
printf("You are the Poor anti-wizard %s. Good Luck!\n",
|
||||
uname);
|
||||
CUMBER = 3;
|
||||
WEIGHT = 9; /* that'll get him! */
|
||||
clock = 10;
|
||||
setbit(location[7].objects, WOODSMAN); /* viper room */
|
||||
setbit(location[20].objects, WOODSMAN); /* laser " */
|
||||
setbit(location[13].objects, DARK); /* amulet " */
|
||||
setbit(location[8].objects, ELF); /* closet */
|
||||
return 0; /* anything else, Chris? */
|
||||
}
|
||||
return 0;
|
||||
}
|
62
games/battlestar/misc.c
Normal file
62
games/battlestar/misc.c
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
card(array, size) /* for beenthere, injuries */
|
||||
register char *array;
|
||||
int size;
|
||||
{
|
||||
register char *end = array + size;
|
||||
register int i = 0;
|
||||
|
||||
while (array < end)
|
||||
if (*array++)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
ucard(array)
|
||||
register unsigned *array;
|
||||
{
|
||||
register int j = 0, n;
|
||||
|
||||
for (n = 0; n < NUMOFOBJECTS; n++)
|
||||
if (testbit(array, n))
|
||||
j++;
|
||||
return (j);
|
||||
}
|
1177
games/battlestar/nightfile.c
Normal file
1177
games/battlestar/nightfile.c
Normal file
File diff suppressed because it is too large
Load Diff
100
games/battlestar/nightobjs.c
Normal file
100
games/battlestar/nightobjs.c
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)nightobjs.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
struct objs nightobjs[] = {
|
||||
{ 218, PAJAMAS },
|
||||
{ 235, NATIVE },
|
||||
{ 92, PAPAYAS },
|
||||
{ 92, PINEAPPLE },
|
||||
{ 92, KIWI },
|
||||
{ 92, MANGO },
|
||||
{ 92, NATIVE },
|
||||
{ 92, MAN },
|
||||
{ 181, LAMPON },
|
||||
{ 236, LAMPON },
|
||||
{ 92, LAMPON },
|
||||
{ 216, WOODSMAN },
|
||||
{ 216, DEADWOOD },
|
||||
{ 216, MALLET },
|
||||
{ 168, WOODSMAN },
|
||||
{ 168, DEADWOOD },
|
||||
{ 168, MALLET },
|
||||
{ 170, WOODSMAN },
|
||||
{ 170, DEADWOOD },
|
||||
{ 170, MALLET },
|
||||
{ 124, SHIELD },
|
||||
{ 124, HALBERD },
|
||||
{ 124, ELF },
|
||||
{ 144, SHIELD },
|
||||
{ 144, HALBERD },
|
||||
{ 144, ELF },
|
||||
{ 113, SHIELD },
|
||||
{ 113, HALBERD },
|
||||
{ 113, ELF },
|
||||
{ 161, SHIELD },
|
||||
{ 161, HALBERD },
|
||||
{ 161, ELF },
|
||||
{ 169, SHIELD },
|
||||
{ 169, HALBERD },
|
||||
{ 169, ELF },
|
||||
{ 182, SHIELD },
|
||||
{ 182, HALBERD },
|
||||
{ 182, ELF },
|
||||
{ 198, SHIELD },
|
||||
{ 198, HALBERD },
|
||||
{ 198, ELF },
|
||||
{ 212, SHIELD },
|
||||
{ 212, HALBERD },
|
||||
{ 212, ELF },
|
||||
{ 216, SHIELD },
|
||||
{ 216, HALBERD },
|
||||
{ 216, ELF },
|
||||
{ 226, SHIELD },
|
||||
{ 226, HALBERD },
|
||||
{ 226, ELF },
|
||||
{ 228, SHIELD },
|
||||
{ 228, HALBERD },
|
||||
{ 228, ELF },
|
||||
{ 68, CYLON },
|
||||
{ 144, SHOVEL },
|
||||
{ 249, FOOT },
|
||||
{ 250, FOOT },
|
||||
{ 93, PAPAYAS },
|
||||
0
|
||||
};
|
101
games/battlestar/parse.c
Normal file
101
games/battlestar/parse.c
Normal file
@ -0,0 +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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
wordinit()
|
||||
{
|
||||
register struct wlist *w;
|
||||
|
||||
for (w = wlist; w->string; w++)
|
||||
install(w);
|
||||
}
|
||||
|
||||
hash(s)
|
||||
register char *s;
|
||||
{
|
||||
register hashval = 0;
|
||||
|
||||
while (*s) {
|
||||
hashval += *s++;
|
||||
hashval *= HASHMUL;
|
||||
hashval &= HASHMASK;
|
||||
}
|
||||
return hashval;
|
||||
}
|
||||
|
||||
struct wlist *
|
||||
lookup(s)
|
||||
char *s;
|
||||
{
|
||||
register 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;
|
||||
{
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
36
games/battlestar/pathnames.h
Normal file
36
games/battlestar/pathnames.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 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.
|
||||
*
|
||||
* @(#)pathnames.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
#define _PATH_SCORE "/var/games/battlestar.log"
|
226
games/battlestar/room.c
Normal file
226
games/battlestar/room.c
Normal file
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)room.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
writedes()
|
||||
{
|
||||
int compass;
|
||||
register char *p;
|
||||
register 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 unsigned int *p = location[position].objects;
|
||||
register 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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
145
games/battlestar/save.c
Normal file
145
games/battlestar/save.c
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
restore()
|
||||
{
|
||||
char *getenv();
|
||||
char *home;
|
||||
char home1[100];
|
||||
register int n;
|
||||
int tmp;
|
||||
register FILE *fp;
|
||||
|
||||
home = getenv("HOME");
|
||||
strcpy(home1, home);
|
||||
strcat(home1, "/Bstar");
|
||||
if ((fp = fopen(home1, "r")) == 0) {
|
||||
perror(home1);
|
||||
return;
|
||||
}
|
||||
fread(&WEIGHT, sizeof WEIGHT, 1, fp);
|
||||
fread(&CUMBER, sizeof CUMBER, 1, fp);
|
||||
fread(&clock, sizeof clock, 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(&time, sizeof time, 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);
|
||||
fread(&ego, sizeof ego, 1, fp);
|
||||
}
|
||||
|
||||
save()
|
||||
{
|
||||
char *getenv();
|
||||
char *home;
|
||||
char home1[100];
|
||||
register int n;
|
||||
int tmp;
|
||||
FILE *fp;
|
||||
|
||||
home = getenv("HOME");
|
||||
strcpy(home1, home);
|
||||
strcat(home1, "/Bstar");
|
||||
if ((fp = fopen(home1, "w")) == 0) {
|
||||
perror(home1);
|
||||
return;
|
||||
}
|
||||
printf("Saved in %s.\n", home1);
|
||||
fwrite(&WEIGHT, sizeof WEIGHT, 1, fp);
|
||||
fwrite(&CUMBER, sizeof CUMBER, 1, fp);
|
||||
fwrite(&clock, sizeof clock, 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(&time, sizeof time, 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);
|
||||
}
|
206
games/battlestar/words.c
Normal file
206
games/battlestar/words.c
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)words.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "externs.h"
|
||||
|
||||
struct wlist wlist[] = {
|
||||
{ "knife", KNIFE, OBJECT },
|
||||
{ "sword", SWORD, NOUNS },
|
||||
{ "scabbard", SWORD, OBJECT },
|
||||
{ "fine", SWORD, OBJECT },
|
||||
{ "two-handed", TWO_HANDED, OBJECT },
|
||||
{ "cleaver", CLEAVER, OBJECT },
|
||||
{ "broadsword", BROAD, OBJECT },
|
||||
{ "mail", MAIL, OBJECT },
|
||||
{ "coat", MAIL, OBJECT },
|
||||
{ "helmet", HELM, OBJECT },
|
||||
{ "shield", SHIELD, OBJECT },
|
||||
{ "maid", MAID, OBJECT },
|
||||
{ "maid's", MAID, OBJECT },
|
||||
{ "body", BODY, NOUNS },
|
||||
{ "viper", VIPER, OBJECT },
|
||||
{ "lamp", LAMPON, OBJECT },
|
||||
{ "lantern", LAMPON, OBJECT },
|
||||
{ "shoes", SHOES, OBJECT },
|
||||
{ "pajamas", PAJAMAS, OBJECT },
|
||||
{ "robe", ROBE, OBJECT },
|
||||
{ "amulet", AMULET, NOUNS },
|
||||
{ "medallion", MEDALION, NOUNS },
|
||||
{ "talisman", TALISMAN, NOUNS },
|
||||
{ "woodsman", DEADWOOD, OBJECT },
|
||||
{ "woodsman's", DEADWOOD, OBJECT },
|
||||
{ "mallet", MALLET, OBJECT },
|
||||
{ "laser", LASER, OBJECT },
|
||||
{ "pistol", LASER, OBJECT },
|
||||
{ "blaster", LASER, OBJECT },
|
||||
{ "gun", LASER, OBJECT },
|
||||
{ "goddess", NORMGOD, NOUNS },
|
||||
{ "grenade", GRENADE, OBJECT },
|
||||
{ "chain", CHAIN, OBJECT },
|
||||
{ "rope", ROPE, OBJECT },
|
||||
{ "levis", LEVIS, OBJECT },
|
||||
{ "pants", LEVIS, OBJECT },
|
||||
{ "mace", MACE, OBJECT },
|
||||
{ "shovel", SHOVEL, OBJECT },
|
||||
{ "halberd", HALBERD, OBJECT },
|
||||
{ "compass", COMPASS, OBJECT },
|
||||
{ "elf", ELF, OBJECT },
|
||||
{ "coins", COINS, OBJECT },
|
||||
{ "matches", MATCHES, OBJECT },
|
||||
{ "match", MATCHES, OBJECT },
|
||||
{ "book", MATCHES, OBJECT },
|
||||
{ "man", MAN, NOUNS },
|
||||
{ "papayas", PAPAYAS, OBJECT },
|
||||
{ "pineapple", PINEAPPLE, OBJECT },
|
||||
{ "kiwi", KIWI, OBJECT },
|
||||
{ "coconuts", COCONUTS, OBJECT },
|
||||
{ "mango", MANGO, OBJECT },
|
||||
{ "ring", RING, OBJECT },
|
||||
{ "potion", POTION, OBJECT },
|
||||
{ "bracelet", BRACELET, OBJECT },
|
||||
{ "timer", TIMER, NOUNS },
|
||||
{ "bomb", BOMB, OBJECT },
|
||||
{ "warhead", BOMB, OBJECT },
|
||||
{ "girl", NATIVE, NOUNS },
|
||||
{ "native", NATIVE, NOUNS },
|
||||
{ "horse", HORSE, OBJECT },
|
||||
{ "stallion", HORSE, OBJECT },
|
||||
{ "car", CAR, OBJECT },
|
||||
{ "volare", CAR, OBJECT },
|
||||
{ "pot", POT, OBJECT },
|
||||
{ "jewels", POT, OBJECT },
|
||||
{ "bar", BAR, OBJECT },
|
||||
{ "diamond", BLOCK, OBJECT },
|
||||
{ "block", BLOCK, OBJECT },
|
||||
{ "up", UP, VERB },
|
||||
{ "u", UP, VERB },
|
||||
{ "down", DOWN, VERB },
|
||||
{ "d", DOWN, VERB },
|
||||
{ "ahead", AHEAD, VERB },
|
||||
{ "a", AHEAD, VERB },
|
||||
{ "back", BACK, VERB },
|
||||
{ "b", BACK, VERB },
|
||||
{ "right", RIGHT, VERB },
|
||||
{ "r", RIGHT, VERB },
|
||||
{ "left", LEFT, VERB },
|
||||
{ "l", LEFT, VERB },
|
||||
{ "take", TAKE, VERB },
|
||||
{ "get", TAKE, VERB },
|
||||
{ "use", USE, VERB },
|
||||
{ "look", LOOK, VERB },
|
||||
{ "lo", LOOK, VERB },
|
||||
{ "quit", QUIT, VERB },
|
||||
{ "q", QUIT, VERB },
|
||||
{ "su", SU, VERB },
|
||||
{ "drop", DROP, VERB },
|
||||
{ "draw", DRAW, VERB },
|
||||
{ "pull", DRAW, VERB },
|
||||
{ "carry", DRAW, VERB },
|
||||
{ "wear", WEARIT, VERB },
|
||||
{ "sheathe", WEARIT, VERB },
|
||||
{ "put", PUT, VERB },
|
||||
{ "buckle", PUT, VERB },
|
||||
{ "strap", PUT, VERB },
|
||||
{ "tie", PUT, VERB },
|
||||
{ "inven", INVEN, VERB },
|
||||
{ "i", INVEN, VERB },
|
||||
{ "everything", EVERYTHING, OBJECT },
|
||||
{ "all", EVERYTHING, OBJECT },
|
||||
{ "and", AND, CONJ },
|
||||
{ "kill", KILL, VERB },
|
||||
{ "fight", KILL, VERB },
|
||||
{ "ravage", RAVAGE, VERB },
|
||||
{ "rape", RAVAGE, VERB },
|
||||
{ "undress", UNDRESS, VERB },
|
||||
{ "throw", THROW, VERB },
|
||||
{ "launch", LAUNCH, VERB },
|
||||
{ "land", LANDIT, VERB },
|
||||
{ "light", LIGHT, VERB },
|
||||
{ "strike", LIGHT, VERB },
|
||||
{ "follow", FOLLOW, VERB },
|
||||
{ "chase", FOLLOW, VERB },
|
||||
{ "kiss", KISS, VERB },
|
||||
{ "love", LOVE, VERB },
|
||||
{ "fuck", LOVE, VERB },
|
||||
{ "give", GIVE, VERB },
|
||||
{ "smite", SMITE, VERB },
|
||||
{ "attack", SMITE, VERB },
|
||||
{ "swing", SMITE, VERB },
|
||||
{ "stab", SMITE, VERB },
|
||||
{ "slice", SMITE, VERB },
|
||||
{ "cut", SMITE, VERB },
|
||||
{ "hack", SMITE, VERB },
|
||||
{ "shoot", SHOOT, VERB },
|
||||
{ "blast", SHOOT, VERB },
|
||||
{ "on", ON, PREPS },
|
||||
{ "off", OFF, PREPS },
|
||||
{ "time", TIME, VERB },
|
||||
{ "sleep", SLEEP, VERB },
|
||||
{ "dig", DIG, VERB },
|
||||
{ "eat", EAT, VERB },
|
||||
{ "swim", SWIM, VERB },
|
||||
{ "drink", DRINK, VERB },
|
||||
{ "door", DOOR, NOUNS },
|
||||
{ "save", SAVE, VERB },
|
||||
{ "ride", RIDE, VERB },
|
||||
{ "mount", RIDE, VERB },
|
||||
{ "drive", DRIVE, VERB },
|
||||
{ "start", DRIVE, VERB },
|
||||
{ "score", SCORE, VERB },
|
||||
{ "points", SCORE, VERB },
|
||||
{ "bury", BURY, VERB },
|
||||
{ "jump", JUMP, VERB },
|
||||
{ "kick", KICK, VERB },
|
||||
{ "kerosene", 0, ADJS },
|
||||
{ "plumed", 0, ADJS },
|
||||
{ "ancient", 0, ADJS },
|
||||
{ "golden", 0, ADJS },
|
||||
{ "gold", 0, ADJS },
|
||||
{ "ostrich", 0, ADJS },
|
||||
{ "rusty", 0, ADJS },
|
||||
{ "old", 0, ADJS },
|
||||
{ "dented", 0, ADJS },
|
||||
{ "blue", 0, ADJS },
|
||||
{ "purple", 0, ADJS },
|
||||
{ "kingly", 0, ADJS },
|
||||
{ "the", 0, ADJS },
|
||||
{ "climb", 0, ADJS },
|
||||
{ "move", 0, ADJS },
|
||||
{ "make", 0, ADJS },
|
||||
{ "to", 0, ADJS },
|
||||
0
|
||||
};
|
9
games/bcd/Makefile
Normal file
9
games/bcd/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
PROG= bcd
|
||||
MAN6= bcd.6
|
||||
MLINKS= bcd.6 morse.6 bcd.6 ppt.6
|
||||
HIDEGAME=hidegame
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
67
games/bcd/bcd.6
Normal file
67
games/bcd/bcd.6
Normal file
@ -0,0 +1,67 @@
|
||||
.\" Copyright (c) 1988, 1991, 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.
|
||||
.\"
|
||||
.\" @(#)bcd.6 8.1 (Berkeley) 5/31/93
|
||||
.\"
|
||||
.Dd May 31, 1993
|
||||
.Dt "BCD" 6
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm bcd ,
|
||||
.Nm ppt ,
|
||||
.Nm morse
|
||||
.Nd "reformat input as punch cards, paper tape or morse code"
|
||||
.Sh SYNOPSIS
|
||||
.Nm bcd
|
||||
.Op Ar string ...
|
||||
.Nm ppt
|
||||
.Op Ar string ...
|
||||
.Nm morse
|
||||
.Op Fl s Ar string ...
|
||||
.Sh DESCRIPTION
|
||||
The commands
|
||||
.Nm bcd ,
|
||||
.Nm ppt
|
||||
and
|
||||
.Nm morse
|
||||
reads the given input and reformats it in the form of punched cards,
|
||||
paper tape or morse code respectively.
|
||||
Acceptable input are command line arguments or the standard input.
|
||||
.Pp
|
||||
Available option:
|
||||
.Bl -tag -width flag
|
||||
.It Fl s
|
||||
The
|
||||
.Fl s
|
||||
option for morse produces dots and dashes rather than words.
|
||||
.El
|
||||
.Sh FILES
|
||||
.SH HISTORY
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user