Use a lookup table to identify whether objects are plural or singular,
instead of testing the final character against 's' in each place. Avoids oddities about "pot of jewels" and "compass".
This commit is contained in:
parent
0fab9d10ca
commit
d3579258c9
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: com2.c,v 1.14 2000/09/22 08:19:21 jsm Exp $ */
|
||||
/* $NetBSD: com2.c,v 1.15 2000/09/23 19:23:57 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)com2.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: com2.c,v 1.14 2000/09/22 08:19:21 jsm Exp $");
|
||||
__RCSID("$NetBSD: com2.c,v 1.15 2000/09/23 19:23:57 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -47,7 +47,6 @@ __RCSID("$NetBSD: com2.c,v 1.14 2000/09/22 08:19:21 jsm Exp $");
|
||||
int
|
||||
wearit()
|
||||
{ /* synonyms = {sheathe, sheath} */
|
||||
int n;
|
||||
int firstnumber, value;
|
||||
|
||||
firstnumber = wordnumber;
|
||||
@ -57,7 +56,6 @@ wearit()
|
||||
value = wordvalue[wordnumber];
|
||||
if (objsht[value] == NULL)
|
||||
break;
|
||||
for (n = 0; objsht[value][n]; n++);
|
||||
switch (value) {
|
||||
|
||||
case -1:
|
||||
@ -65,7 +63,7 @@ wearit()
|
||||
return (firstnumber);
|
||||
|
||||
default:
|
||||
printf("You can't wear%s%s!\n", (objsht[value][n - 1] == 's' ? " " : " a "), objsht[value]);
|
||||
printf("You can't wear%s%s!\n", (is_plural_object(value) ? " " : " a "), objsht[value]);
|
||||
return (firstnumber);
|
||||
|
||||
case KNIFE:
|
||||
@ -94,7 +92,7 @@ wearit()
|
||||
encumber -= objcumber[value];
|
||||
ourtime++;
|
||||
printf("You are now wearing %s %s.\n",
|
||||
(objsht[value][n - 1] == 's' ? "the"
|
||||
(is_plural_object(value) ? "the"
|
||||
: "a"), objsht[value]);
|
||||
} else
|
||||
if (testbit(wear, value))
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: com3.c,v 1.9 2000/09/22 08:19:21 jsm Exp $ */
|
||||
/* $NetBSD: com3.c,v 1.10 2000/09/23 19:23:58 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)com3.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: com3.c,v 1.9 2000/09/22 08:19:21 jsm Exp $");
|
||||
__RCSID("$NetBSD: com3.c,v 1.10 2000/09/23 19:23:58 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -194,7 +194,6 @@ int
|
||||
shoot()
|
||||
{
|
||||
int firstnumber, value;
|
||||
int n;
|
||||
|
||||
firstnumber = wordnumber;
|
||||
if (!testbit(inven, LASER))
|
||||
@ -204,11 +203,11 @@ shoot()
|
||||
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);
|
||||
ourtime++;
|
||||
printf("The %s explode%s\n", objsht[value], (objsht[value][n - 1] == 's' ? (objsht[value][n - 2] == 's' ? "s." : ".") : "s."));
|
||||
printf("The %s explode%s\n", objsht[value],
|
||||
(is_plural_object(value) ? "." : "s."));
|
||||
if (value == BOMB)
|
||||
die();
|
||||
} else
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: com4.c,v 1.13 2000/09/22 12:38:10 jsm Exp $ */
|
||||
/* $NetBSD: com4.c,v 1.14 2000/09/23 19:23:58 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)com4.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: com4.c,v 1.13 2000/09/22 12:38:10 jsm Exp $");
|
||||
__RCSID("$NetBSD: com4.c,v 1.14 2000/09/23 19:23:58 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -49,7 +49,6 @@ take(from)
|
||||
unsigned int from[];
|
||||
{
|
||||
int firstnumber, heavy, bulky, value;
|
||||
int n;
|
||||
|
||||
firstnumber = wordnumber;
|
||||
if (wordnumber < wordcount && wordvalue[wordnumber + 1] == OFF) {
|
||||
@ -61,7 +60,6 @@ take(from)
|
||||
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)) {
|
||||
@ -77,13 +75,18 @@ take(from)
|
||||
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]);
|
||||
printf("You're already holding%s%s.\n",
|
||||
(is_plural_object(value) ? " " : " a "),
|
||||
objsht[value]);
|
||||
else if (!testbit(from, value))
|
||||
printf("I dont see any %s around here.\n", objsht[value]);
|
||||
else if (!heavy)
|
||||
printf("The %s %s too heavy.\n", objsht[value], (objsht[value][n - 1] == 's' ? "are" : "is"));
|
||||
printf("The %s %s too heavy.\n", objsht[value],
|
||||
(is_plural_object(value) ? "are" : "is"));
|
||||
else
|
||||
printf("The %s %s too cumbersome to hold.\n", objsht[value], (objsht[value][n - 1] == 's' ? "are" : "is"));
|
||||
printf("The %s %s too cumbersome to hold.\n",
|
||||
objsht[value],
|
||||
(is_plural_object(value) ? "are" : "is"));
|
||||
if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
|
||||
wordnumber++;
|
||||
else
|
||||
@ -343,6 +346,8 @@ eat()
|
||||
wordnumber++;
|
||||
while (wordnumber <= wordcount) {
|
||||
value = wordvalue[wordnumber];
|
||||
if (wordtype[wordnumber] != OBJECT)
|
||||
value = -1;
|
||||
switch (value) {
|
||||
|
||||
case -1:
|
||||
@ -351,11 +356,8 @@ eat()
|
||||
|
||||
default:
|
||||
printf("You can't eat%s%s!\n",
|
||||
wordtype[wordnumber] == OBJECT &&
|
||||
objsht[value]
|
||||
[strlen(objsht[value]) - 1] == 's' ?
|
||||
" " : " a ",
|
||||
words[wordnumber]);
|
||||
is_plural_object(value) ? " " : " a ",
|
||||
objsht[value]);
|
||||
return (firstnumber);
|
||||
|
||||
case PAPAYAS:
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: extern.h,v 1.21 2000/09/21 17:44:34 jsm Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.22 2000/09/23 19:23:58 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -227,6 +227,9 @@
|
||||
#define MAXWEIGHT 60
|
||||
#define MAXCUMBER 10
|
||||
|
||||
/* Flags for objects. */
|
||||
#define OBJ_PLURAL 1
|
||||
|
||||
struct room {
|
||||
const char *name;
|
||||
int link[8];
|
||||
@ -251,6 +254,8 @@ extern const char *const objsht[NUMOFOBJECTS];
|
||||
extern const char *const ouch[NUMOFINJURIES];
|
||||
extern const int objwt[NUMOFOBJECTS];
|
||||
extern const int objcumber[NUMOFOBJECTS];
|
||||
extern const int objflags[NUMOFOBJECTS];
|
||||
#define is_plural_object(n) (objflags[(n)] & OBJ_PLURAL)
|
||||
|
||||
/* current input line */
|
||||
#define WORDLEN 15
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: globals.c,v 1.13 2000/09/21 17:44:34 jsm Exp $ */
|
||||
/* $NetBSD: globals.c,v 1.14 2000/09/23 19:23:58 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)globals.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: globals.c,v 1.13 2000/09/21 17:44:34 jsm Exp $");
|
||||
__RCSID("$NetBSD: globals.c,v 1.14 2000/09/23 19:23:58 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -220,6 +220,17 @@ const int objcumber[NUMOFOBJECTS] = {
|
||||
10, 8, 8, 10, 10, 3, 1, 2
|
||||
};
|
||||
|
||||
const int objflags[NUMOFOBJECTS] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, OBJ_PLURAL, 0, OBJ_PLURAL,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, OBJ_PLURAL, 0, 0, 0,
|
||||
0, 0, 0, 0, OBJ_PLURAL, 0, 0, OBJ_PLURAL,
|
||||
0, 0, OBJ_PLURAL, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
int win = 1;
|
||||
int matchcount = 20;
|
||||
int followgod = -1;
|
||||
|
Loading…
Reference in New Issue
Block a user