Initial revision

git-svn-id: file:///srv/svn/joey/bsdgames-trunk@5086 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
joey
1999-09-08 23:56:51 +00:00
commit 03272d67da
623 changed files with 243457 additions and 0 deletions

16
adventure/Makefile.bsd Normal file
View File

@@ -0,0 +1,16 @@
# $NetBSD: Makefile,v 1.7 1998/08/01 23:02:35 hubertf Exp $
# @(#)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
MAN= adventure.6
HIDEGAME=hidegame
CLEANFILES+=setup data.c
data.c: glorkz setup
${.OBJDIR}/setup ${.CURDIR}/glorkz > data.c
setup: setup.c hdr.h
${HOST_CC} -o setup ${.CURDIR}/setup.c
.include <bsd.prog.mk>

14
adventure/Makefrag Normal file
View File

@@ -0,0 +1,14 @@
# Makefrag - makefile fragment for adventure
adventure_CLEANFILES := data.c
adventure_DIRS := $(GAMESDIR) $(MAN6DIR)
adventure_all: adventure/adventure adventure/adventure.6
adventure/data.c: adventure/glorkz adventure/setup
adventure/setup $< >$@
adventure_install: adventure_all
$(INSTALL_BINARY) adventure/adventure $(INSTALL_PREFIX)$(GAMESDIR)/adventure
$(HIDE_GAME) adventure
$(INSTALL_MANUAL) adventure/adventure.6

59
adventure/adventure.6 Normal file
View File

@@ -0,0 +1,59 @@
.\" $NetBSD: adventure.6,v 1.3 1997/10/10 11:59:33 lukem Exp $
.\"
.\" 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
.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 .

140
adventure/crc.c Normal file
View File

@@ -0,0 +1,140 @@
/* $NetBSD: crc.c,v 1.6 1998/09/13 00:07:24 hubertf Exp $ */
/*-
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 5/31/93";
static char ORIGINAL_sccsid[] = "@(#)crc.c 5.2 (Berkeley) 4/4/91";
#else
__RCSID("$NetBSD: crc.c,v 1.6 1998/09/13 00:07:24 hubertf Exp $");
#endif
#endif /* not lint */
#include "extern.h"
const unsigned 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.
*/
unsigned long crcval;
unsigned int step;
void
crc_start()
{
crcval = step = 0;
}
unsigned long
crc(ptr, nr) /* Process nr bytes at a time; ptr points to them */
const char *ptr;
int nr;
{
int i;
const char *p;
while (nr > 0)
for (p = ptr; nr--; ++p) {
if (!(i = crcval >> 24 ^ *p)) {
i = step++;
if (step >= sizeof(crctab) / sizeof(crctab[0]))
step = 0;
}
crcval = (crcval << 8) ^ crctab[i];
}
return crcval & 0xffffffff; /* Mask to 32 bits. */
}

174
adventure/done.c Normal file
View File

@@ -0,0 +1,174 @@
/* $NetBSD: done.c,v 1.6 1998/09/13 15:21:36 hubertf Exp $ */
/*-
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)done.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: done.c,v 1.6 1998/09/13 15:21:36 hubertf Exp $");
#endif
#endif /* not lint */
/* Re-coding of advent in C: termination routines */
#include <stdio.h>
#include "hdr.h"
#include "extern.h"
int
score()
{ /* sort of like 20000 */
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);
}
void
done(entry) /* entry=1 means goto 13000 */ /* game is over */
int entry; /* entry=2 means goto 20000 */ /* 3=19000 */
{
int i, sc;
if (entry == 1)
mspeak(1);
if (entry == 3)
rspeak(136);
printf("\n\n\nYou scored %d out of a ", (sc = score()));
printf("possible %d using %d turns.\n", mxscor, turns);
for (i = 1; i <= clsses; i++)
if (cval[i] >= sc) {
speak(&ctext[i]);
if (i == clsses - 1) {
printf("To achieve the next higher rating");
printf(" would be a neat trick!\n\n");
printf("Congratulations!!\n");
exit(0);
}
k = cval[i] + 1 - sc;
printf("To achieve the next higher rating, you need");
printf(" %d more point", k);
if (k == 1)
printf(".\n");
else
printf("s.\n");
exit(0);
}
printf("You just went off my scale!!!\n");
exit(0);
}
void
die(entry) /* label 90 */
int entry;
{
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;
}

130
adventure/extern.h Normal file
View File

@@ -0,0 +1,130 @@
/* $NetBSD: extern.h,v 1.9 1998/09/13 15:21:37 hubertf Exp $ */
/*
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Christos Zoulas.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
/* crc.c */
void crc_start __P((void));
unsigned long crc __P((const char *, int));
/* done.c */
int score __P((void));
void done __P((int)) __attribute__((__noreturn__));
void die __P((int));
/* init.c */
void init __P((void));
char *decr __P((int, int, int, int, int));
void linkdata __P((void));
void trapdel __P((int));
void startup __P((void));
/* io.c */
void getin __P((char **, char **));
int yes __P((int, int, int));
int yesm __P((int, int, int));
int next __P((void));
void rdata __P((void));
int rnum __P((void));
void rdesc __P((int));
void rtrav __P((void));
#ifdef DEBUG
void twrite __P((int));
#endif
void rvoc __P((void));
void rlocs __P((void));
void rdflt __P((void));
void rliq __P((void));
void rhints __P((void));
void rspeak __P((int));
void mspeak __P((int));
struct text;
void speak __P((const struct text *));
void pspeak __P((int, int));
/* save.c */
int save __P((const char *));
int restore __P((const char *));
/* subr.c */
int toting __P((int));
int here __P((int));
int at __P((int));
int liq2 __P((int));
int liq __P((void));
int liqloc __P((int));
int bitset __P((int, int));
int forced __P((int));
int dark __P((void));
int pct __P((int));
int fdwarf __P((void));
int march __P((void));
int mback __P((void));
int specials __P((void));
int trbridge __P((void));
void badmove __P((void));
void bug __P((int)) __attribute__((__noreturn__));
void checkhints __P((void));
int trsay __P((void));
int trtake __P((void));
int dropper __P((void));
int trdrop __P((void));
int tropen __P((void));
int trkill __P((void));
int trtoss __P((void));
int trfeed __P((void));
int trfill __P((void));
void closing __P((void));
void caveclose __P((void));
/* vocab.c */
void dstroy __P((int));
void juggle __P((int));
void move __P((int, int));
int put __P((int, int, int));
void carry __P((int, int));
void drop __P((int, int));
int vocab __P((const char *, int, int));
/* These three used to be functions in vocab.c */
#define copystr(src, dest) strcpy((dest), (src))
#define weq(str1, str2) (!strncmp((str1), (str2), 5))
#define length(str) (strlen((str)) + 1)
void prht __P((void));
/* wizard.c */
void datime __P((int *, int *));
void poof __P((void));
int Start __P((void));
int wizard __P((void));
void ciao __P((void));
int ran __P((int));

1815
adventure/glorkz Normal file

File diff suppressed because it is too large Load Diff

164
adventure/hdr.h Normal file
View File

@@ -0,0 +1,164 @@
/* $NetBSD: hdr.h,v 1.5 1998/08/29 20:19:56 hubertf Exp $ */
/*-
* 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 */
#include <signal.h>
int datfd; /* message file descriptor */
volatile sig_atomic_t delhit;
int yea;
extern char data_file[]; /* Virtual data file */
#define TAB 011
#define LF 012
#define FLUSHLINE do { int flushline_ch; while ((flushline_ch = getchar()) != EOF && flushline_ch != '\n'); } while (0)
#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], links[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 and
* counters */
abbnum, maxdie, numdie, holdng, dkill, foobar, bonus, clock1,
clock2, saved, closng, panic, closed, scorng;
int demo, newloc, limit;
#define DECR(a,b,c,d,e) decr(a+'+',b+'-',c+'#',d+'&',e+'%')

241
adventure/init.c Normal file
View File

@@ -0,0 +1,241 @@
/* $NetBSD: init.c,v 1.10 1998/08/29 20:19:56 hubertf Exp $ */
/*-
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/2/93";
#else
__RCSID("$NetBSD: init.c,v 1.10 1998/08/29 20:19:56 hubertf Exp $");
#endif
#endif /* not lint */
/* Re-coding of advent in C: data initialization */
#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "hdr.h"
#include "extern.h"
int blklin = TRUE;
int setbit[16] = {1, 2, 4, 010, 020, 040, 0100, 0200, 0400, 01000, 02000, 04000,
010000, 020000, 040000, 0100000};
void
init() /* everything for 1st time run */
{
rdata(); /* read data from orig. file */
linkdata();
poof();
}
char *
decr(a, b, c, d, e)
char a, b, c, d, e;
{
static char buf[6];
buf[0] = a - '+';
buf[1] = b - '-';
buf[2] = c - '#';
buf[3] = d - '&';
buf[4] = e - '%';
buf[5] = 0;
return buf;
}
void
linkdata()
{ /* secondary data manipulation */
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, 0);
lamp = vocab(DECR('l', 'a', 'm', 'p', '\0'), 1, 0);
grate = vocab(DECR('g', 'r', 'a', 't', 'e'), 1, 0);
cage = vocab(DECR('c', 'a', 'g', 'e', '\0'), 1, 0);
rod = vocab(DECR('r', 'o', 'd', '\0', '\0'), 1, 0);
rod2 = rod + 1;
steps = vocab(DECR('s', 't', 'e', 'p', 's'), 1, 0);
bird = vocab(DECR('b', 'i', 'r', 'd', '\0'), 1, 0);
door = vocab(DECR('d', 'o', 'o', 'r', '\0'), 1, 0);
pillow = vocab(DECR('p', 'i', 'l', 'l', 'o'), 1, 0);
snake = vocab(DECR('s', 'n', 'a', 'k', 'e'), 1, 0);
fissur = vocab(DECR('f', 'i', 's', 's', 'u'), 1, 0);
tablet = vocab(DECR('t', 'a', 'b', 'l', 'e'), 1, 0);
clam = vocab(DECR('c', 'l', 'a', 'm', '\0'), 1, 0);
oyster = vocab(DECR('o', 'y', 's', 't', 'e'), 1, 0);
magzin = vocab(DECR('m', 'a', 'g', 'a', 'z'), 1, 0);
dwarf = vocab(DECR('d', 'w', 'a', 'r', 'f'), 1, 0);
knife = vocab(DECR('k', 'n', 'i', 'f', 'e'), 1, 0);
food = vocab(DECR('f', 'o', 'o', 'd', '\0'), 1, 0);
bottle = vocab(DECR('b', 'o', 't', 't', 'l'), 1, 0);
water = vocab(DECR('w', 'a', 't', 'e', 'r'), 1, 0);
oil = vocab(DECR('o', 'i', 'l', '\0', '\0'), 1, 0);
plant = vocab(DECR('p', 'l', 'a', 'n', 't'), 1, 0);
plant2 = plant + 1;
axe = vocab(DECR('a', 'x', 'e', '\0', '\0'), 1, 0);
mirror = vocab(DECR('m', 'i', 'r', 'r', 'o'), 1, 0);
dragon = vocab(DECR('d', 'r', 'a', 'g', 'o'), 1, 0);
chasm = vocab(DECR('c', 'h', 'a', 's', 'm'), 1, 0);
troll = vocab(DECR('t', 'r', 'o', 'l', 'l'), 1, 0);
troll2 = troll + 1;
bear = vocab(DECR('b', 'e', 'a', 'r', '\0'), 1, 0);
messag = vocab(DECR('m', 'e', 's', 's', 'a'), 1, 0);
vend = vocab(DECR('v', 'e', 'n', 'd', 'i'), 1, 0);
batter = vocab(DECR('b', 'a', 't', 't', 'e'), 1, 0);
nugget = vocab(DECR('g', 'o', 'l', 'd', '\0'), 1, 0);
coins = vocab(DECR('c', 'o', 'i', 'n', 's'), 1, 0);
chest = vocab(DECR('c', 'h', 'e', 's', 't'), 1, 0);
eggs = vocab(DECR('e', 'g', 'g', 's', '\0'), 1, 0);
tridnt = vocab(DECR('t', 'r', 'i', 'd', 'e'), 1, 0);
vase = vocab(DECR('v', 'a', 's', 'e', '\0'), 1, 0);
emrald = vocab(DECR('e', 'm', 'e', 'r', 'a'), 1, 0);
pyram = vocab(DECR('p', 'y', 'r', 'a', 'm'), 1, 0);
pearl = vocab(DECR('p', 'e', 'a', 'r', 'l'), 1, 0);
rug = vocab(DECR('r', 'u', 'g', '\0', '\0'), 1, 0);
chain = vocab(DECR('c', 'h', 'a', 'i', 'n'), 1, 0);
back = vocab(DECR('b', 'a', 'c', 'k', '\0'), 0, 0);
look = vocab(DECR('l', 'o', 'o', 'k', '\0'), 0, 0);
cave = vocab(DECR('c', 'a', 'v', 'e', '\0'), 0, 0);
null = vocab(DECR('n', 'u', 'l', 'l', '\0'), 0, 0);
entrnc = vocab(DECR('e', 'n', 't', 'r', 'a'), 0, 0);
dprssn = vocab(DECR('d', 'e', 'p', 'r', 'e'), 0, 0);
enter = vocab(DECR('e', 'n', 't', 'e', 'r'), 0, 0);
pour = vocab(DECR('p', 'o', 'u', 'r', '\0'), 2, 0);
say = vocab(DECR('s', 'a', 'y', '\0', '\0'), 2, 0);
lock = vocab(DECR('l', 'o', 'c', 'k', '\0'), 2, 0);
throw = vocab(DECR('t', 'h', 'r', 'o', 'w'), 2, 0);
find = vocab(DECR('f', 'i', 'n', 'd', '\0'), 2, 0);
invent = vocab(DECR('i', 'n', 'v', 'e', 'n'), 2, 0);
/* 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;
}
void
trapdel(n) /* come here if he hits a del */
int n __attribute__((unused));
{
delhit = 1; /* main checks, treats as QUIT */
signal(SIGINT, trapdel);/* catch subsequent DELs */
}
void
startup()
{
demo = Start();
srand((int) (time((time_t *) NULL))); /* random seed */
#if 0
srand(371); /* non-random seed */
#endif
hinted[3] = yes(65, 1, 0);
newloc = 1;
delhit = 0;
limit = 330;
if (hinted[3])
limit = 1000; /* better batteries if instrucs */
}

594
adventure/io.c Normal file
View File

@@ -0,0 +1,594 @@
/* $NetBSD: io.c,v 1.10 1998/09/14 09:29:08 hubertf Exp $ */
/*-
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: io.c,v 1.10 1998/09/14 09:29:08 hubertf Exp $");
#endif
#endif /* not lint */
/* Re-coding of advent in C: file i/o and user i/o */
#include <err.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "hdr.h"
#include "extern.h"
void
getin(wrd1, wrd2) /* get command from user */
char **wrd1, **wrd2; /* no prompt, usually */
{
char *s;
static char wd1buf[MAXSTR], wd2buf[MAXSTR];
int first, numch;
*wrd1 = wd1buf; /* return ptr to internal str */
*wrd2 = wd2buf;
wd2buf[0] = 0; /* in case it isn't set here */
for (s = wd1buf, first = 1, numch = 0;;) {
if ((*s = getchar()) >= 'A' && *s <= 'Z')
*s = *s - ('A' - 'a');
/* convert to upper case */
switch (*s) { /* start reading from user */
case '\n':
*s = 0;
return;
case ' ':
if (s == wd1buf || s == wd2buf) /* initial blank */
continue;
*s = 0;
if (first) { /* finished 1st wd; start 2nd */
first = numch = 0;
s = wd2buf;
break;
} else { /* finished 2nd word */
FLUSHLINE;
*s = 0;
return;
}
case EOF:
printf("user closed input stream, quitting...\n");
exit(0);
default:
if (++numch >= MAXSTR) { /* string too long */
printf("Give me a break!!\n");
wd1buf[0] = wd2buf[0] = 0;
FLUSHLINE;
return;
}
s++;
}
}
}
int
yes(x, y, z) /* confirm with rspeak */
int x, y, z;
{
int result = TRUE; /* pacify gcc */
int ch;
for (;;) {
rspeak(x); /* tell him what we want */
if ((ch = getchar()) == 'y')
result = TRUE;
else if (ch == 'n')
result = FALSE;
else if (ch == EOF) {
printf("user closed input stream, quitting...\n");
exit(0);
}
FLUSHLINE;
if (ch == 'y' || ch == 'n')
break;
printf("Please answer the question.\n");
}
if (result == TRUE)
rspeak(y);
if (result == FALSE)
rspeak(z);
return (result);
}
int
yesm(x, y, z) /* confirm with mspeak */
int x, y, z;
{
int result = TRUE; /* pacify gcc */
int ch;
for (;;) {
mspeak(x); /* tell him what we want */
if ((ch = getchar()) == 'y')
result = TRUE;
else if (ch == 'n')
result = FALSE;
else if (ch == EOF) {
printf("user closed input stream, quitting...\n");
exit(0);
}
FLUSHLINE;
if (ch == 'y' || ch == 'n')
break;
printf("Please answer the question.\n");
}
if (result == TRUE)
mspeak(y);
if (result == FALSE)
mspeak(z);
return (result);
}
/* FILE *inbuf,*outbuf; */
char *inptr; /* Pointer into virtual disk */
int outsw = 0; /* putting stuff to data file? */
const char iotape[] = "Ax3F'\003tt$8h\315qer*h\017nGKrX\207:!l";
const char *tape = iotape; /* pointer to encryption tape */
int
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 */
void
rdata()
{ /* "read" data from virtual file */
int sect;
char ch;
inptr = data_file; /* Pointer to virtual data file */
srandom(SEED); /* which is lightly encrypted. */
clsses = 1;
for (;;) { /* read data sections */
sect = next() - '0'; /* 1st digit of section number */
#ifdef VERBOSE
printf("Section %c", sect + '0');
#endif
if ((ch = next()) != LF) { /* is there a second digit? */
FLUSHLF;
#ifdef VERBOSE
putchar(ch);
#endif
sect = 10 * sect + ch - '0';
}
#ifdef VERBOSE
putchar('\n');
#endif
switch (sect) {
case 0: /* finished reading database */
return;
case 1: /* long form descriptions */
rdesc(1);
break;
case 2: /* short form descriptions */
rdesc(2);
break;
case 3: /* travel table */
rtrav();
break;
case 4: /* vocabulary */
rvoc();
break;
case 5: /* object descriptions */
rdesc(5);
break;
case 6: /* arbitrary messages */
rdesc(6);
break;
case 7: /* object locations */
rlocs();
break;
case 8: /* action defaults */
rdflt();
break;
case 9: /* liquid assets */
rliq();
break;
case 10: /* class messages */
rdesc(10);
break;
case 11: /* hints */
rhints();
break;
case 12: /* magic messages */
rdesc(12);
break;
default:
printf("Invalid data section number: %d\n", sect);
for (;;)
putchar(next());
}
if (breakch != LF) /* routines return after "-1" */
FLUSHLF;
}
}
char nbf[12];
int
rnum()
{ /* read initial location num */
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;
void
rdesc(sect) /* read description-format msgs */
int sect;
{
int locc;
char *seekstart, *maystart;
seekhere = inptr; /* Where are we in virtual file? */
outsw = 1; /* these msgs go into tmp file */
for (oldloc = -1, seekstart = seekhere;;) {
maystart = inptr; /* maybe starting new entry */
if ((locc = rnum()) != oldloc && oldloc >= 0 /* finished msg */
&& !(sect == 5 && (locc == 0 || locc >= 100))) { /* unless sect 5 */
switch (sect) { /* now put it into right table */
case 1:/* long descriptions */
ltext[oldloc].seekadr = seekhere;
ltext[oldloc].txtlen = maystart - seekstart;
break;
case 2:/* short descriptions */
stext[oldloc].seekadr = seekhere;
stext[oldloc].txtlen = maystart - seekstart;
break;
case 5:/* object descriptions */
ptext[oldloc].seekadr = seekhere;
ptext[oldloc].txtlen = maystart - seekstart;
break;
case 6:/* random messages */
if (oldloc > RTXSIZ)
errx(1,"Too many random msgs");
rtext[oldloc].seekadr = seekhere;
rtext[oldloc].txtlen = maystart - seekstart;
break;
case 10: /* class messages */
ctext[clsses].seekadr = seekhere;
ctext[clsses].txtlen = maystart - seekstart;
cval[clsses++] = oldloc;
break;
case 12: /* magic messages */
if (oldloc > MAGSIZ)
errx(1,"Too many magic msgs");
mtext[oldloc].seekadr = seekhere;
mtext[oldloc].txtlen = maystart - seekstart;
break;
default:
errx(1,"rdesc called with bad section");
}
seekhere += maystart - seekstart;
}
if (locc < 0) {
outsw = 0; /* turn off output */
seekhere += 3; /* -1<delimiter> */
return;
}
if (sect != 5 || (locc > 0 && locc < 100)) {
if (oldloc != locc) /* starting a new message */
seekstart = maystart;
oldloc = locc;
}
FLUSHLF; /* scan the line */
}
}
void
rtrav()
{ /* read travel table */
int locc;
struct travlist *t = NULL;
char *s;
char buf[12];
int len, m, n, entries = 0;
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));
if ( t == NULL)
errx(1, "Out of memory!");
/* 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));
if (t == NULL)
errx(1, "Out of memory!");
}
t->tverb = rnum(); /* get verb from the file */
t->tloc = n; /* table entry mod 1000 */
t->conditions = m; /* table entry / 1000 */
/* printf("entry %d for %d\n",entries,locc); */
}
}
}
#ifdef DEBUG
void
twrite(loq) /* travel options from this loc */
int loq;
{
struct travlist *t;
printf("If");
speak(&ltext[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(&ltext[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 */
void
rvoc()
{
char *s; /* read the vocabulary */
int index;
char buf[6];
for (;;) {
index = rnum();
if (index < 0)
break;
for (s = buf, *s = 0;; s++) /* get the word */
if ((*s = next()) == TAB || *s == '\n' || *s == LF
|| *s == ' ')
break;
/* terminate word with newline, LF, tab, blank */
if (*s != '\n' && *s != LF)
FLUSHLF;/* can be comments */
*s = 0;
/* printf("\"%s\"=%d\n",buf,index); */
vocab(buf, -2, index);
}
/* prht(); */
}
void
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;
}
}
void
rdflt()
{ /* default verb messages */
for (;;) {
if ((verb = rnum()) < 0)
break;
actspk[verb] = rnum();
}
}
void
rliq()
{ /* liquid assets &c: cond bits */
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;
}
}
}
void
rhints()
{
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;
}
}
void
rspeak(msg)
int msg;
{
if (msg != 0)
speak(&rtext[msg]);
}
void
mspeak(msg)
int msg;
{
if (msg != 0)
speak(&mtext[msg]);
}
void
speak(msg) /* read, decrypt, and print a message (not
* ptext) */
const struct text *msg; /* msg is a pointer to seek address and length
* of mess */
{
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 */
}
}
void
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 */
{
char *s, nonfirst;
char *numst, save;
struct text *msg;
char *tbuf;
msg = &ptext[m];
if ((tbuf = (char *) malloc(msg->txtlen + 1)) == NULL)
errx(1, "Out of memory!");
memcpy(tbuf, msg->seekadr, msg->txtlen + 1); /* Room to null */
s = tbuf;
nonfirst = 0;
while (s - tbuf < msg->txtlen) { /* read line at a time */
tape = iotape; /* restart decryption tape */
for (numst = s; (*s ^= *tape++) != TAB; s++); /* get number */
save = *s; /* Temporarily trash the string (cringe) */
*s++ = 0; /* decrypting number within the string */
if (atoi(numst) != 100 * skip && skip >= 0) {
while ((*s++ ^ *tape++) != LF) /* flush the line */
if (*tape == 0)
tape = iotape;
continue;
}
if ((*s ^ *tape) == '>' && (*(s + 1) ^ *(tape + 1)) == '$' &&
(*(s + 2) ^ *(tape + 2)) == '<')
break;
if (blklin && !nonfirst++)
putchar('\n');
do {
if (*tape == 0)
tape = iotape;
putchar(*s ^ *tape);
} while ((*s++ ^ *tape++) != LF); /* better end with LF */
if (skip < 0)
break;
}
free(tbuf);
}

768
adventure/main.c Normal file
View File

@@ -0,0 +1,768 @@
/* $NetBSD: main.c,v 1.12 1998/09/14 09:29:08 hubertf Exp $ */
/*-
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/2/93";
#else
__RCSID("$NetBSD: main.c,v 1.12 1998/09/14 09:29:08 hubertf Exp $");
#endif
#endif /* not lint */
/* Re-coding of advent in C: main program */
#include <sys/file.h>
#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include "hdr.h"
#include "extern.h"
int main __P((int, char **));
int
main(argc, argv)
int argc;
char **argv;
{
int i;
int rval, ll;
struct text *kk;
/* revoke setgid privileges */
setregid(getgid(), getgid());
init(); /* Initialize everything */
signal(SIGINT, trapdel);
if (argc > 1) { /* Restore file specified */
/* Restart is label 8305 (Fortran) */
i = restore(argv[1]); /* See what we've got */
switch (i) {
case 0: /* The restore worked fine */
yea = Start();
k = null;
unlink(argv[1]); /* Don't re-use the save */
goto l8; /* Get where we're going */
case 1: /* Couldn't open it */
errx(1,"can't open file"); /* So give up */
case 2: /* Oops -- file was altered */
rspeak(202); /* You dissolve */
exit(1); /* File could be non-adventure */
} /* So don't unlink it. */
}
startup(); /* prepare for a user */
for (;;) { /* main command loop (label 2) */
if (newloc < 9 && newloc != 0 && closng) {
rspeak(130); /* if closing leave only by */
newloc = loc; /* main office */
if (!panic)
clock2 = 15;
panic = TRUE;
}
rval = fdwarf(); /* dwarf stuff */
if (rval == 99)
die(99);
l2000: if (loc == 0)
die(99); /* label 2000 */
kk = &stext[loc];
if ((abb[loc] % abbnum) == 0 || kk->seekadr == 0)
kk = &ltext[loc];
if (!forced(loc) && dark()) {
if (wzdark && pct(35)) {
die(90);
goto l2000;
}
kk = &rtext[16];
}
#if 0
l2001:
#endif
if (toting(bear))
rspeak(141); /* 2001 */
speak(kk);
k = 1;
if (forced(loc))
goto l8;
if (loc == 33 && pct(25) && !closng)
rspeak(8);
if (!dark()) {
abb[loc]++;
for (i = atloc[loc]; i != 0; i = links[i]) { /* 2004 */
obj = i;
if (obj > 100)
obj -= 100;
if (obj == steps && toting(nugget))
continue;
if (prop[obj] < 0) {
if (closed)
continue;
prop[obj] = 0;
if (obj == rug || obj == chain)
prop[obj] = 1;
tally--;
if (tally == tally2 && tally != 0)
if (limit > 35)
limit = 35;
}
ll = prop[obj]; /* 2006 */
if (obj == steps && loc == fixed[steps])
ll = 1;
pspeak(obj, ll);
} /* 2008 */
goto l2012;
l2009: k = 54; /* 2009 */
l2010: spk = k;
l2011: rspeak(spk);
}
l2012: verb = 0; /* 2012 */
obj = 0;
l2600: checkhints(); /* to 2600-2602 */
if (closed) {
if (prop[oyster] < 0 && toting(oyster))
pspeak(oyster, 1);
for (i = 1; i < 100; i++)
if (toting(i) && prop[i] < 0) /* 2604 */
prop[i] = -1 - prop[i];
}
wzdark = dark(); /* 2605 */
if (knfloc > 0 && knfloc != loc)
knfloc = 1;
getin(&wd1, &wd2);
if (delhit) { /* user typed a DEL */
delhit = 0; /* reset counter */
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, 0)))
copystr("pour", wd2);
l2610: if (weq(wd1, "west"))
if (++iwest == 10)
rspeak(17);
l2630: i = vocab(wd1, -1, 0);
if (i == -1) {
spk = 60; /* 3000 */
if (pct(20))
spk = 61;
if (pct(20))
spk = 13;
rspeak(spk);
goto l2600;
}
k = i % 1000;
kq = i / 1000 + 1;
switch (kq) {
case 1:
goto l8;
case 2:
goto l5000;
case 3:
goto l4000;
case 4:
goto l2010;
default:
bug(22);
}
l8:
switch (march()) {
case 2:
continue; /* i.e. goto l2 */
case 99:
die(99);
goto l2000;
default:
bug(110);
}
l2800: 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;
#if 0
l4080:
#endif
switch (verb) {
case 1: /* take = 8010 */
if (atloc[loc] == 0 || links[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, 0);
spk = 42;
if (foobar == 1 - k)
goto l8252;
if (foobar != 0)
spk = 151;
goto l2011;
l8252: foobar = k;
if (k != 4)
goto l2009;
foobar = 0;
if (place[eggs] == plac[eggs]
|| (toting(eggs) && loc == plac[eggs]))
goto l2011;
if (place[eggs] == 0 && place[troll] == 0 && prop[troll] == 0)
prop[troll] = 1;
k = 2;
if (here(eggs))
k = 1;
if (loc == plac[eggs])
k = 0;
move(eggs, plac[eggs]);
pspeak(eggs, k);
goto l2012;
case 26: /* brief=8260 */
spk = 156;
abbnum = 10000;
detail = 3;
goto l2011;
case 27: /* read=8270 */
if (here(magzin))
obj = magzin;
if (here(tablet))
obj = obj * 100 + tablet;
if (here(messag))
obj = obj * 100 + messag;
if (closed && toting(oyster))
obj = oyster;
if (obj > 100 || obj == 0 || dark())
goto l8000;
goto l9270;
case 30: /* suspend=8300 */
spk = 201;
if (demo)
goto l2011;
printf("I can suspend your adventure for you so");
printf(" you can resume later, but\n");
printf("you will have to wait at least");
printf(" %d minutes before continuing.", latncy);
if (!yes(200, 54, 54))
goto l2012;
datime(&saved, &savet);
ciao(); /* Do we quit? */
continue; /* Maybe not */
case 31: /* hours=8310 */
printf("Colossal cave is closed 9am-5pm Mon ");
printf("through Fri except holidays.\n");
goto l2012;
default:
bug(23);
}
l4090:
switch (verb) {
case 1: /* take = 9010 */
l9010: switch (trtake()) {
case 2011:
goto l2011;
case 9220:
goto l9220;
case 2009:
goto l2009;
case 2012:
goto l2012;
default:
bug(102);
}
l9020: case 2: /* drop = 9020 */
switch (trdrop()) {
case 2011:
goto l2011;
case 19000:
done(3);
case 2012:
goto l2012;
default:
bug(105);
}
#if 0
l9030:
#endif
case 3:
switch (trsay()) {
case 2012:
goto l2012;
case 2630:
goto l2630;
default:
bug(107);
}
l9040: case 4:
case 6: /* open, close */
switch (tropen()) {
case 2011:
goto l2011;
case 2010:
goto l2010;
default:
bug(106);
}
case 5:
goto l2009; /* nothing */
case 7: /* on 9070 */
l9070: if (!here(lamp))
goto l2011;
spk = 184;
if (limit < 0)
goto l2011;
prop[lamp] = 1;
rspeak(39);
if (wzdark)
goto l2000;
goto l2012;
case 8: /* off */
l9080: if (!here(lamp))
goto l2011;
prop[lamp] = 0;
rspeak(40);
if (dark())
rspeak(16);
goto l2012;
case 9: /* wave */
if ((!toting(obj)) && (obj != rod || !toting(rod2)))
spk = 29;
if (obj != rod || !at(fissur) || !toting(obj) || closng)
goto l2011;
prop[fissur] = 1 - prop[fissur];
pspeak(fissur, 2 - prop[fissur]);
goto l2012;
case 10:
case 11:
case 18: /* calm, walk, quit */
case 24:
case 25:
case 26: /* score, foo, brief */
case 30:
case 31: /* suspend, hours */
goto l2011;
l9120: case 12:/* kill */
switch (trkill()) {
case 8000:
goto l8000;
case 8:
goto l8;
case 2011:
goto l2011;
case 2608:
goto l2608;
case 19000:
done(3);
default:
bug(112);
}
l9130: case 13:/* pour */
if (obj == bottle || obj == 0)
obj = liq();
if (obj == 0)
goto l8000;
if (!toting(obj))
goto l2011;
spk = 78;
if (obj != oil && obj != water)
goto l2011;
prop[bottle] = 1;
place[obj] = 0;
spk = 77;
if (!(at(plant) || at(door)))
goto l2011;
if (at(door)) {
prop[door] = 0; /* 9132 */
if (obj == oil)
prop[door] = 1;
spk = 113 + prop[door];
goto l2011;
}
spk = 112;
if (obj != water)
goto l2011;
pspeak(plant, prop[plant] + 1);
prop[plant] = (prop[plant] + 2) % 6;
prop[plant2] = prop[plant] / 2;
k = null;
goto l8;
case 14: /* 9140 - eat */
if (obj == food)
goto l8142;
if (obj == bird || obj == snake || obj == clam || obj == oyster
|| obj == dwarf || obj == dragon || obj == troll
|| obj == bear)
spk = 71;
goto l2011;
l9150: case 15:/* 9150 - drink */
if (obj == 0 && liqloc(loc) != water && (liq() != water
|| !here(bottle)))
goto l8000;
if (obj != 0 && obj != water)
spk = 110;
if (spk == 110 || liq() != water || !here(bottle))
goto l2011;
prop[bottle] = 1;
place[water] = 0;
spk = 74;
goto l2011;
case 16: /* 9160: rub */
if (obj != lamp)
spk = 76;
goto l2011;
case 17: /* 9170: throw */
switch (trtoss()) {
case 2011:
goto l2011;
case 9020:
goto l9020;
case 9120:
goto l9120;
case 8:
goto l8;
case 9210:
goto l9210;
default:
bug(113);
}
case 19:
case 20: /* 9190: find, invent */
if (at(obj) || (liq() == obj && at(bottle))
|| k == liqloc(loc))
spk = 94;
for (i = 1; i <= 5; i++)
if (dloc[i] == loc && dflag >= 2 && obj == dwarf)
spk = 94;
if (closed)
spk = 138;
if (toting(obj))
spk = 24;
goto l2011;
l9210: case 21:/* feed */
switch (trfeed()) {
case 2011:
goto l2011;
default:
bug(114);
}
l9220: case 22:/* fill */
switch (trfill()) {
case 2011:
goto l2011;
case 8000:
goto l8000;
case 9020:
goto l9020;
default:
bug(115);
}
l9230: case 23:/* blast */
if (prop[rod2] < 0 || !closed)
goto l2011;
bonus = 133;
if (loc == 115)
bonus = 134;
if (here(rod2))
bonus = 135;
rspeak(bonus);
done(2);
l9270: case 27:/* read */
if (dark())
goto l5190;
if (obj == magzin)
spk = 190;
if (obj == tablet)
spk = 196;
if (obj == messag)
spk = 191;
if (obj == oyster && hinted[2] && toting(oyster))
spk = 194;
if (obj != oyster || hinted[2] || !toting(oyster)
|| !closed)
goto l2011;
hinted[2] = yes(192, 193, 54);
goto l2012;
#if 0
l9280:
#endif
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);
#if 0
l9290:
#endif
case 29: /* wake */
if (obj != dwarf || !closed)
goto l2011;
rspeak(199);
done(3);
default:
bug(24);
}
l5000:
obj = k;
if (fixed[k] != loc && !here(k))
goto l5100;
l5010: if (*wd2 != 0)
goto l2800;
if (verb != 0)
goto l4090;
printf("What do you want to do with the %s?\n", wd1);
goto l2600;
l5100: if (k != grate)
goto l5110;
if (loc == 1 || loc == 4 || loc == 7)
k = dprssn;
if (loc > 9 && loc < 15)
k = entrnc;
if (k != grate)
goto l8;
l5110: if (k != dwarf)
goto l5120;
for (i = 1; i <= 5; i++)
if (dloc[i] == loc && dflag >= 2)
goto l5010;
l5120: if ((liq() == k && here(bottle)) || k == liqloc(loc))
goto l5010;
if (obj != plant || !at(plant2) || prop[plant2] == 0)
goto l5130;
obj = plant2;
goto l5010;
l5130: if (obj != knife || knfloc != loc)
goto l5140;
knfloc = -1;
spk = 116;
goto l2011;
l5140: if (obj != rod || !here(rod2))
goto l5190;
obj = rod2;
goto l5010;
l5190: if ((verb == find || verb == invent) && *wd2 == 0)
goto l5010;
printf("I see no %s here\n", wd1);
goto l2012;
}
}

192
adventure/save.c Normal file
View File

@@ -0,0 +1,192 @@
/* $NetBSD: save.c,v 1.5 1998/09/13 00:07:24 hubertf Exp $ */
/*-
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: save.c,v 1.5 1998/09/13 00:07:24 hubertf Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <stdlib.h>
#include "hdr.h"
#include "extern.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)},
{links, sizeof(links)},
{odloc, sizeof(odloc)},
{place, sizeof(place)},
{prop, sizeof(prop)},
{tk, sizeof(tk)},
{NULL, 0}
};
int
save(outfile) /* Two passes on data: first to get checksum,
* second */
const 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;
}
int
restore(infile)
const char *infile;
{
FILE *in;
struct savestruct *p;
char *s;
long sum, cksum = 0;
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
adventure/setup.c Normal file
View File

@@ -0,0 +1,125 @@
/* $NetBSD: setup.c,v 1.5 1998/09/13 15:23:40 hubertf Exp $ */
/*-
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: setup.c,v 1.5 1998/09/13 15:23:40 hubertf Exp $");
#endif
#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 <stdlib.h>
#include <err.h>
#include "hdr.h" /* SEED lives in there; keep them coordinated. */
#define USAGE "Usage: setup file > data.c (file is typically glorkz)"
#define YES 1
#define NO 0
#define LINE 10 /* How many values do we get on a line? */
int main __P((int, char *[]));
int
main(argc, argv)
int argc;
char *argv[];
{
FILE *infile;
int c, count, linestart;
if (argc != 2)
errx(1, USAGE);
if ((infile = fopen(argv[1], "r")) == NULL)
err(1, "Can't read file %s", 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,", (unsigned int)('\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,", (unsigned int)(c ^ random()) & 0xFF);
}
puts("\n\t0\n};");
fclose(infile);
exit(0);
}

1058
adventure/subr.c Normal file

File diff suppressed because it is too large Load Diff

229
adventure/vocab.c Normal file
View File

@@ -0,0 +1,229 @@
/* $NetBSD: vocab.c,v 1.9 1998/09/14 09:29:09 hubertf Exp $ */
/*-
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)vocab.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: vocab.c,v 1.9 1998/09/14 09:29:09 hubertf Exp $");
#endif
#endif /* not lint */
/* Re-coding of advent in C: data structure routines */
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include "hdr.h"
#include "extern.h"
void
dstroy(object)
int object;
{
move(object, 0);
}
void
juggle(object)
int object;
{
int i, j;
i = place[object];
j = fixed[object];
move(object, i);
move(object + 100, j);
}
void
move(object, where)
int object, where;
{
int from;
if (object <= 100)
from = place[object];
else
from = fixed[object - 100];
if (from > 0 && from <= 300)
carry(object, from);
drop(object, where);
}
int
put(object, where, pval)
int object, where, pval;
{
move(object, where);
return (-1 - pval);
}
void
carry(object, where)
int object, where;
{
int temp;
if (object <= 100) {
if (place[object] == -1)
return;
place[object] = -1;
holdng++;
}
if (atloc[where] == object) {
atloc[where] = links[object];
return;
}
for (temp = atloc[where]; links[temp] != object; temp = links[temp]);
links[temp] = links[object];
}
void
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;
links[object] = atloc[where];
atloc[where] = object;
}
int
vocab(word, type, value) /* look up or store a word */
const char *word;
int type; /* -2 for store, -1 for user word, >=0 for
* canned lookup */
int value; /* used for storing only */
{
int adr;
const char *s;
char *t;
int hash, i;
struct hashtab *h;
for (hash = 0, s = word, i = 0; i < 5 && *s; i++) /* some kind of hash */
hash += *s++; /* add all chars in the word */
hash = (hash * 3719) & 077777; /* pulled that one out of a hat */
hash %= HTSIZE; /* put it into range of table */
for (adr = hash;; adr++) { /* look for entry in table */
if (adr == HTSIZE)
adr = 0;/* wrap around */
h = &voc[adr]; /* point at the entry */
switch (type) {
case -2: /* fill in entry */
if (h->val) /* already got an entry? */
goto exitloop2;
h->val = value;
h->atab = malloc(length(word));
if (h->atab == NULL)
errx(1, "Out of memory!");
for (s = word, t = h->atab; *s;)
*t++ = *s++ ^ '=';
*t = 0 ^ '=';
/* encrypt slightly to thwart core reader */
/* printf("Stored \"%s\" (%d ch) as entry %d\n", */
/* word, 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)
errx(1,"Unable to find %s in vocab", word);
for (s = word, t = h->atab; *t ^ '=';)
if ((*s++ ^ '=') != *t++)
goto exitloop2;
/* the word matched o.k. */
if (h->val / 1000 != type)
continue;
return (h->val % 1000);
}
exitloop2: /* hashed entry does not match */
if (adr + 1 == hash || (adr == HTSIZE && hash == 0))
errx(1,"Hash table overflow");
}
}
void
prht()
{ /* print hash table */
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');
}
}

164
adventure/wizard.c Normal file
View File

@@ -0,0 +1,164 @@
/* $NetBSD: wizard.c,v 1.8 1998/08/24 22:07:37 hubertf Exp $ */
/*-
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)wizard.c 8.1 (Berkeley) 6/2/93";
#else
__RCSID("$NetBSD: wizard.c,v 1.8 1998/08/24 22:07:37 hubertf Exp $");
#endif
#endif /* not lint */
/* Re-coding of advent in C: privileged operations */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "hdr.h"
#include "extern.h"
void
datime(d, t)
int *d, *t;
{
time_t tvec;
struct tm *tptr;
time(&tvec);
tptr = localtime(&tvec);
/* day since 1977 (mod leap) */
*d = (tptr->tm_yday + 365 * (tptr->tm_year - 77)
+ (tptr->tm_year - 77) / 4 - (tptr->tm_year - 1) / 100
+ (tptr->tm_year + 299) / 400);
/* bug: this will overflow in the year 2066 AD (with 16 bit int) */
/* it will be attributed to Wm the C's millenial celebration */
/* and minutes since midnite */
*t = tptr->tm_hour * 60 + tptr->tm_min;
} /* pretty painless */
char magic[6];
void
poof()
{
strcpy(magic, DECR('d', 'w', 'a', 'r', 'f'));
latncy = 45;
}
int
Start()
{
int d, t, delay;
datime(&d, &t);
delay = (d - saved) * 1440 + (t - savet); /* good for about a
* month */
if (delay >= latncy) {
saved = -1;
return (FALSE);
}
printf("This adventure was suspended a mere %d minute%s ago.",
delay, delay == 1 ? "" : "s");
if (delay <= latncy / 3) {
mspeak(2);
exit(0);
}
mspeak(8);
if (!wizard()) {
mspeak(9);
exit(0);
}
saved = -1;
return (FALSE);
}
int
wizard()
{ /* not as complex as advent/10 (for now) */
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);
}
void
ciao()
{
char *c;
char fname[80];
printf("What would you like to call the saved version?\n");
/* XXX - should use fgetln to avoid arbitrary limit */
for (c = fname;; c++) {
int ch;
ch = getchar();
if (ch == '\n' || ch == EOF)
break;
*c = ch;
}
*c = 0;
if (save(fname) != 0)
return; /* Save failed */
printf("To resume, say \"adventure %s\".\n", fname);
printf("\"With these rooms I might now have been familiarly acquainted.\"\n");
exit(0);
}
int
ran(range)
int range;
{
long i;
i = rand() % range;
return (i);
}