diff options
-rw-r--r-- | games/battlestar/battlestar.c | 6 | ||||
-rw-r--r-- | games/battlestar/com2.c | 21 | ||||
-rw-r--r-- | games/battlestar/com4.c | 33 | ||||
-rw-r--r-- | games/battlestar/extern.h | 11 | ||||
-rw-r--r-- | games/battlestar/getcom.c | 41 | ||||
-rw-r--r-- | games/battlestar/globals.c | 6 | ||||
-rw-r--r-- | games/battlestar/parse.c | 55 | ||||
-rw-r--r-- | games/battlestar/words.c | 5 |
8 files changed, 134 insertions, 44 deletions
diff --git a/games/battlestar/battlestar.c b/games/battlestar/battlestar.c index a2875e3b7ea..68210cd6461 100644 --- a/games/battlestar/battlestar.c +++ b/games/battlestar/battlestar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: battlestar.c,v 1.8 2000/07/03 05:23:43 pjanzen Exp $ */ +/* $OpenBSD: battlestar.c,v 1.9 2000/09/17 21:28:30 pjanzen Exp $ */ /* $NetBSD: battlestar.c,v 1.3 1995/03/21 15:06:47 cgd Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)battlestar.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: battlestar.c,v 1.8 2000/07/03 05:23:43 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: battlestar.c,v 1.9 2000/09/17 21:28:30 pjanzen Exp $"; #endif #endif /* not lint */ @@ -100,7 +100,7 @@ start: run: next = getcom(mainbuf, sizeof mainbuf, ">-: ", "Please type in something."); - for (wordcount = 0; next && wordcount < 20; wordcount++) + for (wordcount = 0; next && wordcount < NWORD; wordcount++) next = getword(next, words[wordcount], -1); parse(); switch (cypher()) { diff --git a/games/battlestar/com2.c b/games/battlestar/com2.c index 792e9efe468..dcc5b5d1783 100644 --- a/games/battlestar/com2.c +++ b/games/battlestar/com2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com2.c,v 1.8 2000/07/03 05:23:44 pjanzen Exp $ */ +/* $OpenBSD: com2.c,v 1.9 2000/09/17 21:28:32 pjanzen Exp $ */ /* $NetBSD: com2.c,v 1.3 1995/03/21 15:06:55 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)com2.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: com2.c,v 1.8 2000/07/03 05:23:44 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: com2.c,v 1.9 2000/09/17 21:28:32 pjanzen Exp $"; #endif #endif /* not lint */ @@ -52,7 +52,8 @@ wearit() firstnumber = wordnumber; while (wordtype[++wordnumber] == ADJS); - while (wordnumber <= wordcount) { + while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT || + wordtype[wordnumber] == NOUNS)) { value = wordvalue[wordnumber]; for (n = 0; objsht[value][n]; n++); switch (value) { @@ -90,9 +91,9 @@ wearit() carrying -= objwt[value]; encumber -= objcumber[value]; ourtime++; - printf("You are now wearing %s %s.\n", - (objsht[value][n - 1] == 's' ? "the" : "a"), - objsht[value]); + printf("You are now wearing %s%s.\n", + (objsht[value][n - 1] == 's' ? "the " : + (AorAn(value))), objsht[value]); } else if (TestBit(wear, value)) printf("You are already wearing the %s.\n", @@ -198,11 +199,12 @@ murder() puts("Kill what?"); break; default: - if (wordtype[n] != OBJECT) + if (wordtype[n] != OBJECT || + wordvalue[wordnumber] == EVERYTHING) puts("You can't kill that!"); else printf("You can't kill the %s!\n", - objsht[wordvalue[n]]); + objsht[wordvalue[n]]); break; } } else @@ -263,7 +265,8 @@ murder() break; default: - if (wordtype[wordnumber] != OBJECT) + if (wordtype[wordnumber] != OBJECT || + wordvalue[wordnumber] == EVERYTHING) puts("You can't kill that!"); else printf("You can't kill the %s!\n", diff --git a/games/battlestar/com4.c b/games/battlestar/com4.c index 748f52f7ac9..aed8434e69b 100644 --- a/games/battlestar/com4.c +++ b/games/battlestar/com4.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com4.c,v 1.8 2000/07/03 05:23:44 pjanzen Exp $ */ +/* $OpenBSD: com4.c,v 1.9 2000/09/17 21:28:32 pjanzen Exp $ */ /* $NetBSD: com4.c,v 1.3 1995/03/21 15:07:04 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)com4.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: com4.c,v 1.8 2000/07/03 05:23:44 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: com4.c,v 1.9 2000/09/17 21:28:32 pjanzen Exp $"; #endif #endif /* not lint */ @@ -78,7 +78,9 @@ take(from) 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", + (objsht[value][n-1] == 's' ? "" : + (AorAn(value))), objsht[value]); else if (!heavy) printf("The %s %s too heavy.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is")); else if (!bulky) @@ -281,6 +283,19 @@ drop(name) ; while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) { value = wordvalue[wordnumber]; + if (value == BODY) { /* special case */ + 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; + } if (wordtype[wordnumber] == NOUNS) { if (value == DOOR) puts("You hurt your foot."); @@ -314,8 +329,12 @@ drop(name) else if (*name == 'G') puts("Given anyway."); } - } else + } else if (TestBit(location[position].objects, value)) puts("Kicked."); + else if (TestBit(wear, value)) + puts("Not while it's being worn."); + else + puts("Not found."); } } if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) @@ -357,10 +376,10 @@ eat() return (firstnumber); default: - printf("You can't eat%s%s!\n", + printf("You can't eat %s%s!\n", wordtype[wordnumber] == OBJECT && - objsht[value][strlen(objsht[value]) - 1] == 's' ? " " : " a ", - words[wordnumber]); + objsht[value][strlen(objsht[value]) - 1] == 's' ? "" : + (AorAn(value)), objsht[value]); return (firstnumber); case PAPAYAS: diff --git a/games/battlestar/extern.h b/games/battlestar/extern.h index f42e430a66e..fb8fbcbdc03 100644 --- a/games/battlestar/extern.h +++ b/games/battlestar/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.7 2000/07/24 01:02:44 pjanzen Exp $ */ +/* $OpenBSD: extern.h,v 1.8 2000/09/17 21:28:32 pjanzen Exp $ */ /* $NetBSD: extern.h,v 1.5 1995/04/24 12:22:18 cgd Exp $ */ /* @@ -59,6 +59,8 @@ #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))) + /* "a " vs "an " before an object */ +#define AorAn(value) (strchr("aeiou", objsht[value][0]) ? "an " : "a ") /* well known rooms */ #define FINAL 275 @@ -259,8 +261,9 @@ extern const int objwt[NUMOFOBJECTS]; extern const int objcumber[NUMOFOBJECTS]; /* current input line */ +#define WORDLEN 15 #define NWORD 20 /* words per line */ -extern char words[NWORD][15]; +extern char words[NWORD][WORDLEN]; extern int wordvalue[NWORD]; extern int wordtype[NWORD]; extern int wordcount, wordnumber; @@ -336,8 +339,8 @@ void endfly __P((void)); int fight __P((int, int)); int follow __P((void)); char *getcom __P((char *, int, const char *, const char *)); -char *getword __P((char *, char *, int)); void getutmp __P((char *)); +char *getword __P((char *, char *, int)); int give __P((void)); int hash __P((const char *)); void initialize __P((const char *)); @@ -350,8 +353,8 @@ void light __P((void)); void live __P((void)); struct wlist *lookup __P((const char *)); void love __P((void)); -int moveplayer __P((int, int)); void moveenemy __P((int)); +int moveplayer __P((int, int)); void murder __P((void)); void news __P((void)); void newway __P((int)); diff --git a/games/battlestar/getcom.c b/games/battlestar/getcom.c index 2801fe4a89b..badd560e799 100644 --- a/games/battlestar/getcom.c +++ b/games/battlestar/getcom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getcom.c,v 1.6 1999/09/25 20:30:45 pjanzen Exp $ */ +/* $OpenBSD: getcom.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $ */ /* $NetBSD: getcom.c,v 1.3 1995/03/21 15:07:30 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)getcom.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: getcom.c,v 1.6 1999/09/25 20:30:45 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: getcom.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $"; #endif #endif /* not lint */ @@ -80,6 +80,9 @@ getword(buf1, buf2, flag) char *buf1, *buf2; int flag; { + int cnt; + + cnt = 1; while (isspace(*buf1)) buf1++; if (*buf1 != ',') { @@ -87,24 +90,34 @@ getword(buf1, buf2, flag) *buf2 = 0; return (0); } - while (*buf1 && !isspace(*buf1) && *buf1 != ',') + while (cnt < WORDLEN && *buf1 && !isspace(*buf1) && *buf1 != ',') if (flag < 0) { - if (isupper(*buf1)) + if (isupper(*buf1)) { *buf2++ = tolower(*buf1++); - else + cnt++; + } else { *buf2++ = *buf1++; - } else - if (flag > 0) { - if (islower(*buf1)) - *buf2++ = toupper(*buf1++); - else - *buf2++ = *buf1++; - } else + cnt++; + } + } else if (flag > 0) { + if (islower(*buf1)) { + *buf2++ = toupper(*buf1++); + cnt++; + } else { *buf2++ = *buf1++; + cnt++; + } + } else { + *buf2++ = *buf1++; + cnt++; + } + if (cnt == WORDLEN) + while (*buf1 && !isspace(*buf1)) + buf1++; } else *buf2++ = *buf1++; - *buf2 = 0; + *buf2 = '\0'; while (isspace(*buf1)) buf1++; - return (*buf1 ? buf1 : 0); + return (*buf1 ? buf1 : NULL); } diff --git a/games/battlestar/globals.c b/games/battlestar/globals.c index 3a2e458df90..b686ed2653e 100644 --- a/games/battlestar/globals.c +++ b/games/battlestar/globals.c @@ -1,4 +1,4 @@ -/* $OpenBSD: globals.c,v 1.6 2000/07/03 05:23:45 pjanzen Exp $ */ +/* $OpenBSD: globals.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $ */ /* $NetBSD: globals.c,v 1.3 1995/03/21 15:07:32 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)globals.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: globals.c,v 1.6 2000/07/03 05:23:45 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: globals.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $"; #endif #endif /* not lint */ @@ -228,7 +228,7 @@ int followfight = -1; struct room *location; /* current input line */ -char words[NWORD][15]; +char words[NWORD][WORDLEN]; int wordvalue[NWORD]; int wordtype[NWORD]; int wordcount, wordnumber; diff --git a/games/battlestar/parse.c b/games/battlestar/parse.c index a927124e5cd..9a96dac673a 100644 --- a/games/battlestar/parse.c +++ b/games/battlestar/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.6 1999/09/25 20:30:46 pjanzen Exp $ */ +/* $OpenBSD: parse.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $ */ /* $NetBSD: parse.c,v 1.3 1995/03/21 15:07:48 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)parse.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: parse.c,v 1.6 1999/09/25 20:30:46 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: parse.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $"; #endif #endif /* not lint */ @@ -98,6 +98,7 @@ parse() { struct wlist *wp; int n; + int flag; wordnumber = 0; /* for cypher */ for (n = 0; n <= wordcount; n++) { @@ -109,4 +110,54 @@ parse() wordtype[n] = wp->article; } } + /* Trim "AND AND" which can happen naturally at the end of a + * comma-delimited list + */ + for (n = 1; n < wordcount; n++) + if (wordvalue[n - 1] == AND && wordvalue[n] == AND) { + int i; + for (i = n + 1; i < wordcount; i++) { + wordtype[i - 1] = wordtype[i]; + wordvalue[i - 1] = wordvalue[i]; + strlcpy(words[i - 1], words[i], WORDLEN); + } + wordcount--; + } + + /* If there is a sequence (NOUN | OBJECT) AND EVERYTHING + * then move all the EVERYTHINGs to the beginning, since that's where + * they're expected. We can't get rid of the NOUNs and OBJECTs in + * case they aren't in EVERYTHING (i.e. not here or nonexistant). + */ + flag = 1; + while (flag) { + flag = 0; + for (n = 1; n < wordcount; n++) + if ((wordtype[n - 1] == NOUNS || wordtype[n - 1] == OBJECT) && + wordvalue[n] == AND && wordvalue[n + 1] == EVERYTHING) { + char tmpword[WORDLEN]; + wordvalue[n + 1] = wordvalue[n - 1]; + wordvalue[n - 1] = EVERYTHING; + wordtype[n + 1] = wordtype[n - 1]; + wordtype[n - 1] = OBJECT; + strlcpy(tmpword, words[n - 1], WORDLEN); + strlcpy(words[n - 1], words[n + 1], WORDLEN); + strlcpy(words[n + 1], tmpword, WORDLEN); + flag = 1; + } + /* And trim EVERYTHING AND EVERYTHING */ + for (n = 1; n < wordcount; n++) + if (wordvalue[n - 1] == EVERYTHING && + wordvalue[n] == AND && wordvalue[n + 1] == EVERYTHING) { + int i; + for (i = n + 1; i < wordcount; i++) { + wordtype[i - 1] = wordtype[i + 1]; + wordvalue[i - 1] = wordvalue[i + 1]; + strlcpy(words[i - 1], words[i + 1], WORDLEN); + } + wordcount--; + wordcount--; + flag = 1; + } + } } diff --git a/games/battlestar/words.c b/games/battlestar/words.c index 02f9fe14ca8..10da4fc1079 100644 --- a/games/battlestar/words.c +++ b/games/battlestar/words.c @@ -1,4 +1,4 @@ -/* $OpenBSD: words.c,v 1.6 2000/07/03 05:23:46 pjanzen Exp $ */ +/* $OpenBSD: words.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $ */ /* $NetBSD: words.c,v 1.3 1995/03/21 15:08:00 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)words.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: words.c,v 1.6 2000/07/03 05:23:46 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: words.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $"; #endif #endif /* not lint */ @@ -150,6 +150,7 @@ struct wlist wlist[] = { { "everything", EVERYTHING, OBJECT, NULL }, { "all", EVERYTHING, OBJECT, NULL }, { "and", AND, CONJ, NULL }, + { ",", AND, CONJ, NULL }, { "kill", KILL, VERB, NULL }, { "fight", KILL, VERB, NULL }, { "ravage", RAVAGE, VERB, NULL }, |