diff options
-rw-r--r-- | games/battlestar/battlestar.6 | 19 | ||||
-rw-r--r-- | games/battlestar/battlestar.c | 20 | ||||
-rw-r--r-- | games/battlestar/com1.c | 50 | ||||
-rw-r--r-- | games/battlestar/com2.c | 80 | ||||
-rw-r--r-- | games/battlestar/com3.c | 80 | ||||
-rw-r--r-- | games/battlestar/com4.c | 70 | ||||
-rw-r--r-- | games/battlestar/com5.c | 30 | ||||
-rw-r--r-- | games/battlestar/com6.c | 32 | ||||
-rw-r--r-- | games/battlestar/com7.c | 36 | ||||
-rw-r--r-- | games/battlestar/cypher.c | 54 | ||||
-rw-r--r-- | games/battlestar/dayfile.c | 6 | ||||
-rw-r--r-- | games/battlestar/dayobjs.c | 10 | ||||
-rw-r--r-- | games/battlestar/extern.h | 120 | ||||
-rw-r--r-- | games/battlestar/fly.c | 6 | ||||
-rw-r--r-- | games/battlestar/getcom.c | 6 | ||||
-rw-r--r-- | games/battlestar/globals.c | 52 | ||||
-rw-r--r-- | games/battlestar/init.c | 68 | ||||
-rw-r--r-- | games/battlestar/misc.c | 14 | ||||
-rw-r--r-- | games/battlestar/nightfile.c | 6 | ||||
-rw-r--r-- | games/battlestar/nightobjs.c | 10 | ||||
-rw-r--r-- | games/battlestar/parse.c | 10 | ||||
-rw-r--r-- | games/battlestar/pathnames.h | 3 | ||||
-rw-r--r-- | games/battlestar/room.c | 14 | ||||
-rw-r--r-- | games/battlestar/save.c | 98 | ||||
-rw-r--r-- | games/battlestar/words.c | 6 |
25 files changed, 505 insertions, 395 deletions
diff --git a/games/battlestar/battlestar.6 b/games/battlestar/battlestar.6 index 52298da022b..0fc591bbeda 100644 --- a/games/battlestar/battlestar.6 +++ b/games/battlestar/battlestar.6 @@ -1,4 +1,4 @@ -.\" $OpenBSD: battlestar.6,v 1.5 1999/07/09 13:35:55 aaron Exp $ +.\" $OpenBSD: battlestar.6,v 1.6 1999/09/25 20:30:45 pjanzen Exp $ .\" $NetBSD: battlestar.6,v 1.4 1995/03/21 15:06:42 cgd Exp $ .\" .\" Copyright (c) 1983, 1993 @@ -42,7 +42,8 @@ .Nd a tropical adventure game .Sh SYNOPSIS .Nm battlestar -.Op -r | saved-file +.Op Fl r +.Op Ar saved-file .Sh DESCRIPTION .Nm is an adventure game in the classic style. However, it's slightly less @@ -129,11 +130,23 @@ will print out your current status in the game. The command .Dq save will save your game in a file called -.Pa ~/Bstar . +.Pa ~/Bstar +by default. You can recover a saved game by using the .Fl r option when you start up the game, or by giving the name of the saved file as an argument. +Save files will be saved to and restored from your home directory unless a +path is specified \- i.e., +.Dq Li battlestar -r savedgame +will look for +.Pa ~/savedgame , +but +.Dq Li battlestar -r ./savedgame +will look in the current directory. +.Dq Li battlestar -r +will look for the default file, +.Pa ~/Bstar . .Sh DIRECTIONS The compass directions N, S, E, and W can be used if you have a compass. If you don't have a compass, you'll have to say R, L, A, or B, which diff --git a/games/battlestar/battlestar.c b/games/battlestar/battlestar.c index 785f3b0d60a..d408710eff7 100644 --- a/games/battlestar/battlestar.c +++ b/games/battlestar/battlestar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: battlestar.c,v 1.6 1998/09/13 01:30:30 pjanzen Exp $ */ +/* $OpenBSD: battlestar.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: battlestar.c,v 1.3 1995/03/21 15:06:47 cgd Exp $ */ /* @@ -42,9 +42,9 @@ static char copyright[] = #ifndef lint #if 0 -static char sccsid[] = "@(#)battlestar.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)battlestar.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: battlestar.c,v 1.6 1998/09/13 01:30:30 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: battlestar.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -56,6 +56,7 @@ static char rcsid[] = "$OpenBSD: battlestar.c,v 1.6 1998/09/13 01:30:30 pjanzen */ #include "extern.h" +#include "pathnames.h" int main __P((int, char *[])); @@ -73,7 +74,12 @@ main(argc, argv) setegid(getgid()); setgid(getgid()); - initialize(argc < 2 || strcmp(argv[1], "-r")); + if (argc < 2) + initialize(NULL); + else if (strcmp(argv[1], "-r") == 0) + initialize((argc > 2) ? argv[2] : DEFAULT_SAVE_FILE); + else + initialize(argv[1]); start: news(); beenthere[position]++; @@ -83,8 +89,8 @@ start: puts("Your match splutters out."); matchlight = 0; } - if (!notes[CANTSEE] || testbit(inven, LAMPON) || - testbit(location[position].objects, LAMPON)) { + if (!notes[CANTSEE] || TestBit(inven, LAMPON) || + TestBit(location[position].objects, LAMPON)) { writedes(); printobjs(); } else @@ -102,6 +108,6 @@ run: case 0: goto start; default: - exit(1); + errx(1, "bad return from cypher(): please submit a bug report"); } } diff --git a/games/battlestar/com1.c b/games/battlestar/com1.c index 9d88e5481da..9f95e97af6a 100644 --- a/games/battlestar/com1.c +++ b/games/battlestar/com1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com1.c,v 1.6 1998/09/13 01:30:30 pjanzen Exp $ */ +/* $OpenBSD: com1.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: com1.c,v 1.3 1995/03/21 15:06:51 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)com1.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)com1.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: com1.c,v 1.6 1998/09/13 01:30:30 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: com1.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -50,7 +50,7 @@ move(thataway, token) { wordnumber++; if ((!notes[CANTMOVE] && !notes[LAUNCHED]) || - testbit(location[position].objects, LAND) || + TestBit(location[position].objects, LAND) || (fuel > 0 && notes[LAUNCHED])) { if (thataway) { position = thataway; @@ -74,7 +74,7 @@ void convert(tothis) /* Converts day to night and vice versa. */ int tothis; /* Day objects are permanent. Night objects */ { /* are added at dusk, and subtracted at dawn.*/ - struct objs *p; + const struct objs *p; unsigned int i, j; if (tothis == TONIGHT) { @@ -82,14 +82,14 @@ convert(tothis) /* Converts day to night and vice versa. */ for (j = 0; j < NUMOFWORDS; j++) nightfile[i].objects[j] = dayfile[i].objects[j]; for (p = nightobjs; p->room != 0; p++) - setbit(nightfile[p->room].objects, p->obj); + SetBit(nightfile[p->room].objects, p->obj); location = nightfile; } else { for (i = 1; i <= NUMOFROOMS; i++) for (j = 0; j < NUMOFWORDS; j++) dayfile[i].objects[j] = nightfile[i].objects[j]; for (p = nightobjs; p->room != 0; p++) - clearbit(dayfile[p->room].objects, p->obj); + ClearBit(dayfile[p->room].objects, p->obj); location = dayfile; } } @@ -124,7 +124,7 @@ news() } } else { convert(TONIGHT); - clearbit(location[POOLS].objects, BATHGOD); + ClearBit(location[POOLS].objects, BATHGOD); if (OUTSIDE && ourtime - rythmn - CYCLE < 10) { puts("The dying sun sinks into the ocean, leaving a blood stained sunset."); puts("The sky slowly fades from orange to violet to black. A few stars"); @@ -135,19 +135,19 @@ news() rythmn = ourtime - ourtime % CYCLE; } if (!wiz && !tempwiz) - if ((testbit(inven, TALISMAN) || testbit(wear, TALISMAN)) && (testbit(inven, MEDALION) || testbit(wear, MEDALION)) && (testbit(inven, AMULET) || testbit(wear, AMULET))) { + if ((TestBit(inven, TALISMAN) || TestBit(wear, TALISMAN)) && (TestBit(inven, MEDALION) || TestBit(wear, MEDALION)) && (TestBit(inven, AMULET) || TestBit(wear, AMULET))) { tempwiz = 1; puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard."); } - if (testbit(location[position].objects, ELF)) { + if (TestBit(location[position].objects, ELF)) { printf("%s\n", objdes[ELF]); fight(ELF, rnd(30)); } - if (testbit(location[position].objects, DARK)) { + if (TestBit(location[position].objects, DARK)) { printf("%s\n", objdes[DARK]); fight(DARK, 100); } - if (testbit(location[position].objects, WOODSMAN)) { + if (TestBit(location[position].objects, WOODSMAN)) { printf("%s\n", objdes[WOODSMAN]); fight(WOODSMAN, 50); } @@ -167,24 +167,24 @@ news() notes[CANTSEE] = 0; break; } - if (testbit(location[position].objects, GIRL)) + if (TestBit(location[position].objects, GIRL)) meetgirl = 1; if (meetgirl && CYCLE * 1.5 - ourtime < 10) { - setbit(location[GARDEN].objects, GIRLTALK); - setbit(location[GARDEN].objects, LAMPON); - setbit(location[GARDEN].objects, ROPE); + SetBit(location[GARDEN].objects, GIRLTALK); + SetBit(location[GARDEN].objects, LAMPON); + SetBit(location[GARDEN].objects, ROPE); } if (position == DOCK && (beenthere[position] || ourtime > CYCLE)) { - clearbit(location[DOCK].objects, GIRL); - clearbit(location[DOCK].objects, MAN); + ClearBit(location[DOCK].objects, GIRL); + ClearBit(location[DOCK].objects, MAN); } if (meetgirl && ourtime - CYCLE * 1.5 > 10) { - clearbit(location[GARDEN].objects, GIRLTALK); - clearbit(location[GARDEN].objects, LAMPON); - clearbit(location[GARDEN].objects, ROPE); + ClearBit(location[GARDEN].objects, GIRLTALK); + ClearBit(location[GARDEN].objects, LAMPON); + ClearBit(location[GARDEN].objects, ROPE); meetgirl = 0; } - if (testbit(location[position].objects, CYLON)) { + if (TestBit(location[position].objects, CYLON)) { puts("Oh my God, you're being shot at by an alien spacecraft!"); printf("The targeting computer says we have %d seconds to attack!\n", ourclock); @@ -197,7 +197,7 @@ news() puts("The viper shudders under a terrible explosion."); printf("I'm afraid you have suffered %s.\n", ouch[hurt]); } else - clearbit(location[position].objects, CYLON); + ClearBit(location[position].objects, CYLON); } if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) { puts("I'm afraid you have suffered fatal injuries."); @@ -236,7 +236,7 @@ crash() fuel--; if (!location[position].flyhere || - (testbit(location[position].objects, LAND) && fuel <= 0)) { + (TestBit(location[position].objects, LAND) && fuel <= 0)) { if (!location[position].flyhere) puts("You're flying too low. We're going to crash!"); else { @@ -249,7 +249,7 @@ crash() position = location[position].down; } notes[LAUNCHED] = 0; - setbit(location[position].objects, CRASH); + SetBit(location[position].objects, CRASH); ourtime += rnd(CYCLE / 4); puts("The viper explodes into the ground and you lose consciousness..."); zzz(); diff --git a/games/battlestar/com2.c b/games/battlestar/com2.c index 3f55fbc9a63..19d91083257 100644 --- a/games/battlestar/com2.c +++ b/games/battlestar/com2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com2.c,v 1.6 1998/09/13 01:30:30 pjanzen Exp $ */ +/* $OpenBSD: com2.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: com2.c,v 1.3 1995/03/21 15:06:55 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)com2.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)com2.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: com2.c,v 1.6 1998/09/13 01:30:30 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: com2.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -84,9 +84,9 @@ wearit() case BRACELET: case GRENADE: - if (testbit(inven, value)) { - clearbit(inven, value); - setbit(wear, value); + if (TestBit(inven, value)) { + ClearBit(inven, value); + SetBit(wear, value); carrying -= objwt[value]; encumber -= objcumber[value]; ourtime++; @@ -94,7 +94,7 @@ wearit() (objsht[value][n - 1] == 's' ? "the" : "a"), objsht[value]); } else - if (testbit(wear, value)) + if (TestBit(wear, value)) printf("You are already wearing the %s.\n", objsht[value]); else @@ -137,10 +137,10 @@ int use() { while (wordtype[++wordnumber] == ADJS && wordnumber < wordcount); - if (wordvalue[wordnumber] == AMULET && testbit(inven, AMULET) && + if (wordvalue[wordnumber] == AMULET && TestBit(inven, AMULET) && position != FINAL) { puts("The amulet begins to glow."); - if (testbit(inven, MEDALION)) { + if (TestBit(inven, MEDALION)) { puts("The medallion comes to life too."); if (position == 114) { location[position].down = 160; @@ -162,7 +162,7 @@ use() } else if (position == FINAL) puts("The amulet won't work in here."); - else if (wordvalue[wordnumber] == COMPASS && testbit(inven, COMPASS)) + else if (wordvalue[wordnumber] == COMPASS && TestBit(inven, COMPASS)) printf("Your compass points %s.\n", truedirec(NORTH,'-')); else if (wordvalue[wordnumber] == COMPASS) puts("You aren't holding the compass."); @@ -178,7 +178,7 @@ murder() { int n; - for (n = 0; !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE || n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL || n == HALBERD) && testbit(inven, n)) && n < NUMOFOBJECTS; n++); + for (n = 0; !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE || n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL || n == HALBERD) && TestBit(inven, n)) && n < NUMOFOBJECTS; n++); if (n == NUMOFOBJECTS) puts("You don't have suitable weapons to kill."); else { @@ -187,17 +187,17 @@ murder() switch (wordvalue[wordnumber]) { case NORMGOD: - if (testbit(location[position].objects, BATHGOD)) { + if (TestBit(location[position].objects, BATHGOD)) { puts("The goddess's head slices off. Her corpse floats in the water."); - clearbit(location[position].objects, BATHGOD); - setbit(location[position].objects, DEADGOD); + ClearBit(location[position].objects, BATHGOD); + SetBit(location[position].objects, DEADGOD); power += 5; notes[JINXED]++; } else - if (testbit(location[position].objects, NORMGOD)) { + if (TestBit(location[position].objects, NORMGOD)) { puts("The goddess pleads but you strike her mercilessly. Her broken body lies in a\npool of blood."); - clearbit(location[position].objects, NORMGOD); - setbit(location[position].objects, DEADGOD); + ClearBit(location[position].objects, NORMGOD); + SetBit(location[position].objects, DEADGOD); power += 5; notes[JINXED]++; if (wintime) @@ -206,27 +206,27 @@ murder() puts("I dont see her anywhere."); break; case TIMER: - if (testbit(location[position].objects, TIMER)) { + if (TestBit(location[position].objects, TIMER)) { puts("The old man offers no resistance."); - clearbit(location[position].objects, TIMER); - setbit(location[position].objects, DEADTIME); + ClearBit(location[position].objects, TIMER); + SetBit(location[position].objects, DEADTIME); power++; notes[JINXED]++; } else puts("Who?"); break; case NATIVE: - if (testbit(location[position].objects, NATIVE)) { + if (TestBit(location[position].objects, NATIVE)) { puts("The girl screams as you cut her body to shreds. She is dead."); - clearbit(location[position].objects, NATIVE); - setbit(location[position].objects, DEADNATIVE); + ClearBit(location[position].objects, NATIVE); + SetBit(location[position].objects, DEADNATIVE); power += 5; notes[JINXED]++; } else puts("What girl?"); break; case MAN: - if (testbit(location[position].objects, MAN)) { + if (TestBit(location[position].objects, MAN)) { puts("You strike him to the ground, and he coughs up blood."); puts("Your fantasy is over."); die(0); @@ -249,7 +249,7 @@ void ravage() { while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount); - if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects, wordvalue[wordnumber])) { + if (wordtype[wordnumber] == NOUNS && TestBit(location[position].objects, wordvalue[wordnumber])) { ourtime++; switch (wordvalue[wordnumber]) { case NORMGOD: @@ -273,18 +273,18 @@ ravage() murder(); if (rnd(100) < 50) { puts("Her screams have attracted attention. I think we are surrounded."); - setbit(location[ahead].objects, WOODSMAN); - setbit(location[ahead].objects, DEADWOOD); - setbit(location[ahead].objects, MALLET); - setbit(location[back].objects, WOODSMAN); - setbit(location[back].objects, DEADWOOD); - setbit(location[back].objects, MALLET); - setbit(location[left].objects, WOODSMAN); - setbit(location[left].objects, DEADWOOD); - setbit(location[left].objects, MALLET); - setbit(location[right].objects, WOODSMAN); - setbit(location[right].objects, DEADWOOD); - setbit(location[right].objects, MALLET); + SetBit(location[ahead].objects, WOODSMAN); + SetBit(location[ahead].objects, DEADWOOD); + SetBit(location[ahead].objects, MALLET); + SetBit(location[back].objects, WOODSMAN); + SetBit(location[back].objects, DEADWOOD); + SetBit(location[back].objects, MALLET); + SetBit(location[left].objects, WOODSMAN); + SetBit(location[left].objects, DEADWOOD); + SetBit(location[left].objects, MALLET); + SetBit(location[right].objects, WOODSMAN); + SetBit(location[right].objects, DEADWOOD); + SetBit(location[right].objects, MALLET); } break; default: @@ -303,15 +303,15 @@ follow() puts("You have cornered him. His laser sword extends as he steps forward."); position = FINAL; fight(DARK, 75); - setbit(location[position].objects, TALISMAN); - setbit(location[position].objects, AMULET); + SetBit(location[position].objects, TALISMAN); + SetBit(location[position].objects, AMULET); return (0); } else if (followgod == ourtime) { puts("The goddess leads you down a steamy tunnel and into a high, wide chamber."); puts("She sits down on a throne."); position = 268; - setbit(location[position].objects, NORMGOD); + SetBit(location[position].objects, NORMGOD); notes[CANTSEE] = 1; return (0); } else diff --git a/games/battlestar/com3.c b/games/battlestar/com3.c index fd8d6aef21a..cc24bf7bcfc 100644 --- a/games/battlestar/com3.c +++ b/games/battlestar/com3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com3.c,v 1.5 1998/09/13 01:30:30 pjanzen Exp $ */ +/* $OpenBSD: com3.c,v 1.6 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: com3.c,v 1.3 1995/03/21 15:07:00 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)com3.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)com3.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: com3.c,v 1.5 1998/09/13 01:30:30 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: com3.c,v 1.6 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -47,16 +47,16 @@ static char rcsid[] = "$OpenBSD: com3.c,v 1.5 1998/09/13 01:30:30 pjanzen Exp $" void dig() { - if (testbit(inven, SHOVEL)) { + if (TestBit(inven, SHOVEL)) { puts("OK"); ourtime++; switch (position) { case 144: /* copse near beach */ if (!notes[DUG]) { - setbit(location[position].objects, DEADWOOD); - setbit(location[position].objects, COMPASS); - setbit(location[position].objects, KNIFE); - setbit(location[position].objects, MACE); + SetBit(location[position].objects, DEADWOOD); + SetBit(location[position].objects, COMPASS); + SetBit(location[position].objects, KNIFE); + SetBit(location[position].objects, MACE); notes[DUG] = 1; } break; @@ -99,9 +99,9 @@ jump() puts("Ahhhhhhh..."); injuries[12] = injuries[8] = injuries[7] = injuries[6] = 1; for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(inven, n)) { - clearbit(inven, n); - setbit(location[position].objects, n); + if (TestBit(inven, n)) { + ClearBit(inven, n); + SetBit(location[position].objects, n); } carrying = 0; encumber = 0; @@ -113,22 +113,22 @@ bury() { int value; - if (testbit(inven, SHOVEL)) { + if (TestBit(inven, SHOVEL)) { while (wordtype[++wordnumber] != OBJECT && wordtype[wordnumber] != NOUNS && wordnumber < wordcount); value = wordvalue[wordnumber]; - if (wordtype[wordnumber] == NOUNS && (testbit(location[position].objects, value) || value == BODY)) + if (wordtype[wordnumber] == NOUNS && (TestBit(location[position].objects, value) || value == BODY)) switch (value) { case BODY: wordtype[wordnumber] = OBJECT; - if (testbit(inven, MAID) || testbit(location[position].objects, MAID)) + if (TestBit(inven, MAID) || TestBit(location[position].objects, MAID)) value = MAID; - if (testbit(inven, DEADWOOD) || testbit(location[position].objects, DEADWOOD)) + if (TestBit(inven, DEADWOOD) || TestBit(location[position].objects, DEADWOOD)) value = DEADWOOD; - if (testbit(inven, DEADGOD) || testbit(location[position].objects, DEADGOD)) + if (TestBit(inven, DEADGOD) || TestBit(location[position].objects, DEADGOD)) value = DEADGOD; - if (testbit(inven, DEADTIME) || testbit(location[position].objects, DEADTIME)) + if (TestBit(inven, DEADTIME) || TestBit(location[position].objects, DEADTIME)) value = DEADTIME; - if (testbit(inven, DEADNATIVE) || testbit(location[position].objects, DEADNATIVE)) + if (TestBit(inven, DEADNATIVE) || TestBit(location[position].objects, DEADNATIVE)) value = DEADNATIVE; break; @@ -147,14 +147,14 @@ bury() default: puts("Wha..?"); } - if (wordtype[wordnumber] == OBJECT && position > 88 && (testbit(inven, value) || testbit(location[position].objects, value))) { + if (wordtype[wordnumber] == OBJECT && position > 88 && (TestBit(inven, value) || TestBit(location[position].objects, value))) { puts("Buried."); - if (testbit(inven, value)) { - clearbit(inven, value); + if (TestBit(inven, value)) { + ClearBit(inven, value); carrying -= objwt[value]; encumber -= objcumber[value]; } - clearbit(location[position].objects, value); + ClearBit(location[position].objects, value); switch (value) { case MAID: case DEADWOOD: @@ -175,11 +175,11 @@ drink() { int n; - if (testbit(inven, POTION)) { + if (TestBit(inven, POTION)) { puts("The cool liquid runs down your throat but turns to fire and you choke."); puts("The heat reaches your limbs and tingles your spirit. You feel like falling"); puts("asleep."); - clearbit(inven, POTION); + ClearBit(inven, POTION); WEIGHT = MAXWEIGHT; CUMBER = MAXCUMBER; for (n = 0; n < NUMOFINJURIES; n++) @@ -197,7 +197,7 @@ shoot() int n; firstnumber = wordnumber; - if (!testbit(inven, LASER)) + if (!TestBit(inven, LASER)) puts("You aren't holding a blaster."); else { while(wordtype[++wordnumber] == ADJS); @@ -205,8 +205,8 @@ shoot() 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); + 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.")); if (value == BOMB) @@ -251,22 +251,22 @@ shoot() break; case NORMGOD: - if (testbit(location[position].objects, BATHGOD)) { + if (TestBit(location[position].objects, BATHGOD)) { puts("The goddess is hit in the chest and splashes back against the rocks."); puts("Dark blood oozes from the charred blast hole. Her naked body floats in the"); puts("pools and then off downstream."); - clearbit(location[position].objects, BATHGOD); - setbit(location[180].objects, DEADGOD); + ClearBit(location[position].objects, BATHGOD); + SetBit(location[180].objects, DEADGOD); power += 5; ego -= 10; notes[JINXED]++; } else - if (testbit(location[position].objects, NORMGOD)) { + if (TestBit(location[position].objects, NORMGOD)) { puts("The blast catches the goddess in the stomach, knocking her to the ground."); puts("She writhes in the dirt as the agony of death taunts her."); puts("She has stopped moving."); - clearbit(location[position].objects, NORMGOD); - setbit(location[position].objects, DEADGOD); + ClearBit(location[position].objects, NORMGOD); + SetBit(location[position].objects, DEADGOD); power += 5; ego -= 10; notes[JINXED]++; @@ -278,18 +278,18 @@ shoot() break; case TIMER: - if (testbit(location[position].objects, TIMER)) { + if (TestBit(location[position].objects, TIMER)) { puts("The old man slumps over the bar."); power++; ego -= 2; notes[JINXED]++; - clearbit(location[position].objects, TIMER); - setbit(location[position].objects, DEADTIME); + ClearBit(location[position].objects, TIMER); + SetBit(location[position].objects, DEADTIME); } else puts("What old-timer?"); break; case MAN: - if (testbit(location[position].objects, MAN)) { + if (TestBit(location[position].objects, MAN)) { puts("The man falls to the ground with blood pouring all over his white suit."); puts("Your fantasy is over."); die(0); @@ -297,10 +297,10 @@ shoot() puts("What man?"); break; case NATIVE: - if (testbit(location[position].objects, NATIVE)) { + if (TestBit(location[position].objects, NATIVE)) { puts("The girl is blown backwards several feet and lies in a pool of blood."); - clearbit(location[position].objects, NATIVE); - setbit(location[position].objects, DEADNATIVE); + ClearBit(location[position].objects, NATIVE); + SetBit(location[position].objects, DEADNATIVE); power += 5; ego -= 2; notes[JINXED]++; diff --git a/games/battlestar/com4.c b/games/battlestar/com4.c index b923590395f..a7972db8e25 100644 --- a/games/battlestar/com4.c +++ b/games/battlestar/com4.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com4.c,v 1.6 1998/09/13 01:30:30 pjanzen Exp $ */ +/* $OpenBSD: com4.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: com4.c,v 1.3 1995/03/21 15:07:04 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)com4.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)com4.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: com4.c,v 1.6 1998/09/13 01:30:30 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: com4.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -64,20 +64,20 @@ take(from) for (n = 0; objsht[value][n]; n++); heavy = (carrying + objwt[value]) <= WEIGHT; bulky = (encumber + objcumber[value]) <= CUMBER; - if ((testbit(from, value) || wiz || tempwiz) && heavy && bulky && !testbit(inven, value)) { - setbit(inven, value); + if ((TestBit(from, value) || wiz || tempwiz) && heavy && bulky && !TestBit(inven, value)) { + SetBit(inven, value); carrying += objwt[value]; encumber += objcumber[value]; ourtime++; - if (testbit(from, value)) + if (TestBit(from, value)) printf("Taken.\n"); else printf("Zap! Taken from thin air.\n"); - clearbit(from, value); + ClearBit(from, value); if (value == MEDALION) win--; } else - if (testbit(inven, value)) + if (TestBit(inven, value)) printf("You're already holding%s%s.\n", (objsht[value][n-1] == 's' ? " " : " a "), objsht[value]); else if (!heavy) printf("The %s %s too heavy.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is")); @@ -97,11 +97,11 @@ take(from) switch (wordvalue[wordnumber]) { case SWORD: - if (testbit(from, SWORD)) { + if (TestBit(from, SWORD)) { wordtype[wordnumber--] = OBJECT; return (take(from)); } - if (testbit(from, TWO_HANDED)) { + if (TestBit(from, TWO_HANDED)) { wordvalue[wordnumber] = TWO_HANDED; wordtype[wordnumber--] = OBJECT; return (take(from)); @@ -111,22 +111,22 @@ take(from) return (take(from)); case BODY: - if (testbit(from, MAID)) { + if (TestBit(from, MAID)) { wordvalue[wordnumber] = MAID; wordtype[wordnumber--] = OBJECT; return (take(from)); } - else if (testbit(from, DEADWOOD)) { + else if (TestBit(from, DEADWOOD)) { wordvalue[wordnumber] = DEADWOOD; wordtype[wordnumber--] = OBJECT; return (take(from)); } - else if (testbit(from, DEADNATIVE)) { + else if (TestBit(from, DEADNATIVE)) { wordvalue[wordnumber] = DEADNATIVE; wordtype[wordnumber--] = OBJECT; return (take(from)); } - else if (testbit(from, DEADGOD)) { + else if (TestBit(from, DEADGOD)) { wordvalue[wordnumber] = DEADGOD; wordtype[wordnumber--] = OBJECT; return (take(from)); @@ -138,7 +138,7 @@ take(from) break; case AMULET: - if (testbit(location[position].objects, AMULET)) { + if (TestBit(location[position].objects, AMULET)) { puts("The amulet is warm to the touch, and its beauty catches your breath."); puts("A mist falls over your eyes, but then it is gone. Sounds seem clearer"); puts("and sharper but far away as if in a dream. The sound of purling water reaches"); @@ -149,7 +149,7 @@ take(from) return (take(from)); case MEDALION: - if (testbit(location[position].objects, MEDALION)) { + if (TestBit(location[position].objects, MEDALION)) { puts("The medallion is warm, and it rekindles your spirit with the warmth of life."); puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate."); } @@ -157,14 +157,14 @@ take(from) return (take(from)); case TALISMAN: - if (testbit(location[position].objects, TALISMAN)) { + if (TestBit(location[position].objects, TALISMAN)) { puts("The talisman is cold to the touch, and it sends a chill down your spine."); } wordtype[wordnumber--] = OBJECT; return (take(from)); case NORMGOD: - if (testbit(location[position].objects, BATHGOD) && (testbit(wear, AMULET) || testbit(inven, AMULET))) { + if (TestBit(location[position].objects, BATHGOD) && (TestBit(wear, AMULET) || TestBit(inven, AMULET))) { puts("She offers a delicate hand, and you help her out of the sparkling springs."); puts("Water droplets like liquid silver bedew her golden skin, but when they part"); puts("from her, they fall as teardrops. She wraps a single cloth around her and"); @@ -172,9 +172,9 @@ take(from) puts("She bids you to follow her."); pleasure++; followgod = ourtime; - clearbit(location[position].objects, BATHGOD); + ClearBit(location[position].objects, BATHGOD); } else - if (!testbit(location[position].objects, BATHGOD)) + if (!TestBit(location[position].objects, BATHGOD)) puts("You're in no position to take her."); else puts("She moves away from you."); @@ -190,7 +190,7 @@ take(from) int throw(name) - char *name; + const char *name; { unsigned int n; int deposit = 0; @@ -228,15 +228,15 @@ throw(name) while (wordtype[++wordnumber] == ADJS); while (wordnumber <= wordcount) { value = wordvalue[wordnumber]; - if (deposit && testbit(location[position].objects, value)) { - clearbit(location[position].objects, value); + if (deposit && TestBit(location[position].objects, value)) { + ClearBit(location[position].objects, value); if (value != GRENADE) - setbit(location[deposit].objects, value); + SetBit(location[deposit].objects, value); else { puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel."); for (n = 0; n < NUMOFWORDS; n++) location[deposit].objects[n] = 0; - setbit(location[deposit].objects, CHAR); + SetBit(location[deposit].objects, CHAR); } if (value == ROPE && position == FINAL) location[position].access = 1; @@ -255,7 +255,7 @@ throw(name) puts("The door is not damaged."); } } else - if (value == GRENADE && testbit(location[position].objects, value)) { + if (value == GRENADE && TestBit(location[position].objects, value)) { puts("You are blown into shreds when your grenade explodes."); die(0); } @@ -271,7 +271,7 @@ throw(name) int drop(name) - char *name; + const char *name; { int firstnumber, value; @@ -281,8 +281,8 @@ drop(name) while (wordnumber <= wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) { value = wordvalue[wordnumber]; printf("%s:\n", objsht[value]); - if (testbit(inven, value)) { - clearbit(inven, value); + if (TestBit(inven, value)) { + ClearBit(inven, value); carrying -= objwt[value]; encumber -= objcumber[value]; if (value == BOMB) { @@ -290,7 +290,7 @@ drop(name) die(0); } if (value != AMULET && value != MEDALION && value != TALISMAN) - setbit(location[position].objects, value); + SetBit(location[position].objects, value); else tempwiz = 0; ourtime++; @@ -301,7 +301,7 @@ drop(name) } else { if (*name != 'K') { printf("You aren't holding the %s.\n", objsht[value]); - if (testbit(location[position].objects, value)) { + if (TestBit(location[position].objects, value)) { if (*name == 'T') puts("Kicked instead."); else if (*name == 'G') @@ -362,9 +362,9 @@ eat() case MANGO: printf("%s:\n", objsht[value]); - if (testbit(inven, value) && ourtime > ate - CYCLE && - testbit(inven, KNIFE)) { - clearbit(inven, value); + if (TestBit(inven, value) && ourtime > ate - CYCLE && + TestBit(inven, KNIFE)) { + ClearBit(inven, value); carrying -= objwt[value]; encumber -= objcumber[value]; ate = max(ourtime, ate) + CYCLE / 3; @@ -374,7 +374,7 @@ eat() } else if (ourtime < ate - CYCLE) puts("You're stuffed."); - else if (!testbit(inven, KNIFE)) + else if (!TestBit(inven, KNIFE)) puts("You need a knife."); else printf("You aren't holding the %s.\n", objsht[value]); diff --git a/games/battlestar/com5.c b/games/battlestar/com5.c index e70321863eb..2b77dd3b350 100644 --- a/games/battlestar/com5.c +++ b/games/battlestar/com5.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com5.c,v 1.4 1998/09/13 01:30:30 pjanzen Exp $ */ +/* $OpenBSD: com5.c,v 1.5 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: com5.c,v 1.3 1995/03/21 15:07:07 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)com5.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)com5.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: com5.c,v 1.4 1998/09/13 01:30:30 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: com5.c,v 1.5 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -49,7 +49,7 @@ kiss() { while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount); if (wordtype[wordnumber] == NOUNS && - testbit(location[position].objects, wordvalue[wordnumber])) { + TestBit(location[position].objects, wordvalue[wordnumber])) { pleasure++; printf("Kissed.\n"); switch (wordvalue[wordnumber]) { @@ -91,7 +91,7 @@ love() int n; while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount); - if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects, wordvalue[wordnumber])) { + if (wordtype[wordnumber] == NOUNS && TestBit(location[position].objects, wordvalue[wordnumber])) { if (wordvalue[wordnumber] == NORMGOD && !loved) { if (godready >= 2) { puts("She cuddles up to you, and her mouth starts to work:\n'That was my sister's amulet. The lovely goddess, Purl, was she. The Empire\ncaptured her just after the Darkness came. My other sister, Vert, was killed\nby the Dark Lord himself. He took her amulet and warped its power.\nYour quest was foretold by my father before he died, but to get the Dark Lord's\namulet you must use cunning and skill. I will leave you my amulet,"); @@ -108,7 +108,7 @@ love() } printf("Goddess:\n"); if (!loved) - setbit(location[position].objects, MEDALION); + SetBit(location[position].objects, MEDALION); loved = 1; ourtime += 10; zzz(); @@ -158,11 +158,11 @@ zzz() case 0: if (ucard(inven)) { n = rnd(NUMOFOBJECTS); - while (!testbit(inven, n)) + while (!TestBit(inven, n)) n = rnd(NUMOFOBJECTS); - clearbit(inven, n); + ClearBit(inven, n); if (n != AMULET && n != MEDALION && n != TALISMAN) - setbit(location[position].objects, n); + SetBit(location[position].objects, n); carrying -= objwt[n]; encumber -= objcumber[n]; } @@ -170,10 +170,10 @@ zzz() fight(ELF, 10); break; case 1: - setbit(location[position].objects, DEADWOOD); + SetBit(location[position].objects, DEADWOOD); break; case 2: - setbit(location[position].objects, HALBERD); + SetBit(location[position].objects, HALBERD); break; default: break; @@ -273,7 +273,7 @@ give() * that's no worse than what other commands than give do in * the same place. */ wordnumber = last1 - 1; - if (person && testbit(location[position].objects, person)) { + if (person && TestBit(location[position].objects, person)) { if (person == NORMGOD && godready < 2 && !(obj == RING || obj == BRACELET)) puts("The goddess won't look at you."); else @@ -283,8 +283,8 @@ give() wordnumber = max(last1, last2) + 1; return (0); } - if (result != -1 && (testbit(location[position].objects, obj) || obj == AMULET || obj == MEDALION || obj == TALISMAN)) { - clearbit(location[position].objects, obj); + if (result != -1 && (TestBit(location[position].objects, obj) || obj == AMULET || obj == MEDALION || obj == TALISMAN)) { + ClearBit(location[position].objects, obj); ourtime++; ego++; switch (person) { @@ -313,7 +313,7 @@ give() puts("She becomes bored and takes several more natives as husbands. One evening,"); puts("after having been out drinking with the girls, she kicks the throne particularly"); puts("hard and wakes you up. (If you want to win this game, you're going to have to\nshoot her!)"); - clearbit(location[position].objects, MEDALION); + ClearBit(location[position].objects, MEDALION); wintime = ourtime; } } diff --git a/games/battlestar/com6.c b/games/battlestar/com6.c index 6926acc024b..7b9f9eebfc1 100644 --- a/games/battlestar/com6.c +++ b/games/battlestar/com6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com6.c,v 1.10 1999/07/31 18:11:26 pjanzen Exp $ */ +/* $OpenBSD: com6.c,v 1.11 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: com6.c,v 1.5 1995/04/27 21:30:23 mycroft Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)com6.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)com6.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: com6.c,v 1.10 1999/07/31 18:11:26 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: com6.c,v 1.11 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -48,9 +48,9 @@ static char rcsid[] = "$OpenBSD: com6.c,v 1.10 1999/07/31 18:11:26 pjanzen Exp $ int launch() { - if (testbit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) { + if (TestBit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) { if (fuel > 4) { - clearbit(location[position].objects, VIPER); + ClearBit(location[position].objects, VIPER); position = location[position].up; notes[LAUNCHED] = 1; ourtime++; @@ -68,11 +68,11 @@ launch() int land() { - if (notes[LAUNCHED] && testbit(location[position].objects, LAND) && + if (notes[LAUNCHED] && TestBit(location[position].objects, LAND) && location[position].down) { notes[LAUNCHED] = 0; position = location[position].down; - setbit(location[position].objects, VIPER); + SetBit(location[position].objects, VIPER); fuel -= 2; ourtime++; puts("You are down."); @@ -124,7 +124,7 @@ post(ch) date[24] = '\0'; if (score_fp != NULL) { - fprintf(score_fp, "%s %8s %c%20s", date, uname, ch, rate()); + fprintf(score_fp, "%s %8s %c%20s", date, username, ch, rate()); if (wiz) fprintf(score_fp, " wizard\n"); else @@ -136,7 +136,7 @@ post(ch) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); } -char * +const char * rate() { int score; @@ -175,11 +175,11 @@ rate() int drive() { - if (testbit(location[position].objects, CAR)) { + if (TestBit(location[position].objects, CAR)) { puts("You hop in the car and turn the key. There is a perceptible grating noise,"); puts("and an explosion knocks you unconscious..."); - clearbit(location[position].objects, CAR); - setbit(location[position].objects, CRASH); + ClearBit(location[position].objects, CAR); + SetBit(location[position].objects, CRASH); injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1; ourtime += 15; zzz(); @@ -192,12 +192,12 @@ drive() int ride() { - if (testbit(location[position].objects, HORSE)) { + if (TestBit(location[position].objects, HORSE)) { puts("You climb onto the stallion and kick it in the guts. The stupid steed launches"); puts("forward through bush and fern. You are thrown and the horse gallops off."); - clearbit(location[position].objects, HORSE); + ClearBit(location[position].objects, HORSE); while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere); - setbit(location[position].objects, HORSE); + SetBit(location[position].objects, HORSE); if (location[position].north) position = location[position].north; else if (location[position].south) @@ -215,7 +215,7 @@ ride() void light() { /* synonyms = {strike, smoke} */ - if (testbit(inven, MATCHES) && matchcount) { + if (TestBit(inven, MATCHES) && matchcount) { puts("Your match splutters to life."); ourtime++; matchlight = 1; diff --git a/games/battlestar/com7.c b/games/battlestar/com7.c index 85b1642556e..eb02f15a74a 100644 --- a/games/battlestar/com7.c +++ b/games/battlestar/com7.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com7.c,v 1.6 1998/09/13 01:30:31 pjanzen Exp $ */ +/* $OpenBSD: com7.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: com7.c,v 1.3 1995/03/21 15:07:12 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)com7.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)com7.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: com7.c,v 1.6 1998/09/13 01:30:31 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: com7.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -74,11 +74,11 @@ fighton: case KILL: case SMITE: - if (testbit(inven, TWO_HANDED)) + if (TestBit(inven, TWO_HANDED)) hurt = rnd(70) - 2 * card(injuries, NUMOFINJURIES) - ucard(wear) - exhaustion; - else if (testbit(inven, SWORD) || testbit(inven, BROAD)) + else if (TestBit(inven, SWORD) || TestBit(inven, BROAD)) hurt = rnd(50) % (WEIGHT - carrying) - card(injuries, NUMOFINJURIES) - encumber - exhaustion; - else if (testbit(inven, KNIFE) || testbit(inven, MALLET) || testbit(inven, CHAIN) || testbit(inven, MACE) || testbit(inven, HALBERD)) + else if (TestBit(inven, KNIFE) || TestBit(inven, MALLET) || TestBit(inven, CHAIN) || TestBit(inven, MACE) || TestBit(inven, HALBERD)) hurt = rnd(15) - card(injuries, NUMOFINJURIES) - exhaustion; else hurt = rnd(7) - encumber; @@ -176,22 +176,22 @@ fighton: case BACK: if (enemy == DARK && lifeline > strength * 0.33) { puts("He throws you back against the rock and pummels your face."); - if (testbit(inven, AMULET) || testbit(wear, AMULET)) { + if (TestBit(inven, AMULET) || TestBit(wear, AMULET)) { printf("Lifting the amulet from you, "); - if (testbit(inven, MEDALION) || testbit(wear, MEDALION)) { + if (TestBit(inven, MEDALION) || TestBit(wear, MEDALION)) { puts("his power grows and the walls of\nthe earth tremble."); puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse."); puts("The planet is consumed by darkness."); die(0); } - if (testbit(inven, AMULET)) { - clearbit(inven, AMULET); + if (TestBit(inven, AMULET)) { + ClearBit(inven, AMULET); carrying -= objwt[AMULET]; encumber -= objcumber[AMULET]; } else - clearbit(wear, AMULET); + ClearBit(wear, AMULET); puts("he flees down the dark caverns."); - clearbit(location[position].objects, DARK); + ClearBit(location[position].objects, DARK); injuries[SKULL] = 1; followfight = ourtime; return (0); @@ -216,14 +216,14 @@ fighton: } case SHOOT: - if (testbit(inven, LASER)) { + if (TestBit(inven, LASER)) { if (strength - lifeline <= 50) { printf("The %s took a direct hit!\n", objsht[enemy]); lifeline += 50; } else { puts("With his bare hand he deflects the laser blast and whips the pistol from you!"); - clearbit(inven, LASER); - setbit(location[position].objects, LASER); + ClearBit(inven, LASER); + SetBit(location[position].objects, LASER); carrying -= objwt[LASER]; encumber -= objcumber[LASER]; } @@ -246,15 +246,15 @@ fighton: printf("You have killed the %s.\n", objsht[enemy]); if (enemy == ELF || enemy == DARK) puts("A watery black smoke consumes his body and then vanishes with a peal of thunder!"); - clearbit(location[position].objects, enemy); + ClearBit(location[position].objects, enemy); power += 2; notes[JINXED]++; return (0); } puts("He attacks..."); /* some embellishments */ - hurt = rnd(NUMOFINJURIES) - (testbit(inven, SHIELD) != 0) - (testbit(wear, MAIL) != 0) - (testbit(wear, HELM) != 0); - hurt += (testbit(wear, AMULET) != 0) + (testbit(wear, MEDALION) != 0) + (testbit(wear, TALISMAN) != 0); + hurt = rnd(NUMOFINJURIES) - (TestBit(inven, SHIELD) != 0) - (TestBit(wear, MAIL) != 0) - (TestBit(wear, HELM) != 0); + hurt += (TestBit(wear, AMULET) != 0) + (TestBit(wear, MEDALION) != 0) + (TestBit(wear, TALISMAN) != 0); hurt = hurt < 0 ? 0 : hurt; hurt = hurt >= NUMOFINJURIES ? NUMOFINJURIES - 1 : hurt; if (!injuries[hurt]) { diff --git a/games/battlestar/cypher.c b/games/battlestar/cypher.c index 1de4e44fbe0..8c41f0d8611 100644 --- a/games/battlestar/cypher.c +++ b/games/battlestar/cypher.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cypher.c,v 1.6 1998/09/13 01:30:31 pjanzen Exp $ */ +/* $OpenBSD: cypher.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: cypher.c,v 1.3 1995/03/21 15:07:15 cgd Exp $ */ /* @@ -36,13 +36,14 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)cypher.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)cypher.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: cypher.c,v 1.6 1998/09/13 01:30:31 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: cypher.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ #include "extern.h" +#include "pathnames.h" int cypher() @@ -51,6 +52,8 @@ cypher() int junk; int lflag = -1; char buffer[10]; + char *filename, *rfilename; + size_t filename_len; while (wordtype[wordnumber] == ADJS) wordnumber++; @@ -103,7 +106,7 @@ cypher() case SHOOT: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(location[position].objects, n) && objsht[n]) { + if (TestBit(location[position].objects, n) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = shoot(); } @@ -116,7 +119,7 @@ cypher() case TAKE: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(location[position].objects, n) && objsht[n]) { + if (TestBit(location[position].objects, n) && objsht[n]) { wordvalue[wordnumber + 1] = n; /* Some objects (type NOUNS) have special treatment in take(). For these * we must set the type to NOUNS. However for SWORD and BODY all it does @@ -128,6 +131,7 @@ cypher() switch (n) { case BATHGOD: wordvalue[wordnumber + 1] = NORMGOD; + /* FALLTHROUGH */ case NORMGOD: case AMULET: case MEDALION: @@ -151,7 +155,7 @@ cypher() case DROP: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(inven, n)) { + if (TestBit(inven, n)) { wordvalue[wordnumber + 1] = n; wordnumber = drop("Dropped"); } @@ -166,8 +170,8 @@ cypher() case THROW: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(inven, n) || - (testbit(location[position].objects, n) && objsht[n])) { + if (TestBit(inven, n) || + (TestBit(location[position].objects, n) && objsht[n])) { wordvalue[wordnumber + 1] = n; wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); } @@ -179,7 +183,7 @@ cypher() case TAKEOFF: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(wear, n)) { + if (TestBit(wear, n)) { wordvalue[wordnumber + 1] = n; wordnumber = takeoff(); } @@ -191,7 +195,7 @@ cypher() case DRAW: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(wear, n)) { + if (TestBit(wear, n)) { wordvalue[wordnumber + 1] = n; wordnumber = draw(); } @@ -203,7 +207,7 @@ cypher() case PUTON: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(location[position].objects, n) && objsht[n]) { + if (TestBit(location[position].objects, n) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = puton(); } @@ -215,7 +219,7 @@ cypher() case WEARIT: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(inven, n)) { + if (TestBit(inven, n)) { wordvalue[wordnumber + 1] = n; wordnumber = wearit(); } @@ -227,7 +231,7 @@ cypher() case EAT: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(inven, n)) { + if (TestBit(inven, n)) { wordvalue[wordnumber + 1] = n; wordnumber = eat(); } @@ -244,7 +248,7 @@ cypher() if (ucard(inven)) { puts("You are holding:\n"); for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(inven, n)) + if (TestBit(inven, n)) printf("\t%s\n", objsht[n]); printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."), (WEIGHT ? carrying * 100 / WEIGHT : -1)); printf("Your arms are %d%% full.\n", encumber * 100 / CUMBER); @@ -254,7 +258,7 @@ cypher() if (ucard(wear)) { puts("\nYou are wearing:\n"); for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(wear, n)) + if (TestBit(wear, n)) printf("\t%s\n", objsht[n]); } else puts("\nYou are stark naked."); @@ -273,8 +277,8 @@ cypher() break; case LOOK: - if (!notes[CANTSEE] || testbit(inven, LAMPON) || - testbit(location[position].objects, LAMPON) + if (!notes[CANTSEE] || TestBit(inven, LAMPON) || + TestBit(location[position].objects, LAMPON) || matchlight) { beenthere[position] = 2; writedes(); @@ -349,7 +353,21 @@ cypher() break; case SAVE: - save(); + printf("\nSave file name (default %s): ", + DEFAULT_SAVE_FILE); + filename = fgetln(stdin, &filename_len); + if (filename_len == 0 + || (filename_len == 1 && filename[0] == '\n')) + rfilename = save_file_name(DEFAULT_SAVE_FILE, + strlen(DEFAULT_SAVE_FILE)); + else { + if (filename[filename_len - 1] == '\n') + filename_len--; + rfilename = save_file_name(filename, + filename_len); + } + save(rfilename); + free(rfilename); break; case FOLLOW: diff --git a/games/battlestar/dayfile.c b/games/battlestar/dayfile.c index b07fd37c4b2..401cb578e57 100644 --- a/games/battlestar/dayfile.c +++ b/games/battlestar/dayfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dayfile.c,v 1.5 1999/07/31 18:11:26 pjanzen Exp $ */ +/* $OpenBSD: dayfile.c,v 1.6 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: dayfile.c,v 1.3 1995/03/21 15:07:18 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)dayfile.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)dayfile.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: dayfile.c,v 1.5 1999/07/31 18:11:26 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: dayfile.c,v 1.6 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ diff --git a/games/battlestar/dayobjs.c b/games/battlestar/dayobjs.c index 26bc307e2a5..61413a9cba3 100644 --- a/games/battlestar/dayobjs.c +++ b/games/battlestar/dayobjs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dayobjs.c,v 1.4 1998/09/13 01:30:31 pjanzen Exp $ */ +/* $OpenBSD: dayobjs.c,v 1.5 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: dayobjs.c,v 1.3 1995/03/21 15:07:22 cgd Exp $ */ /* @@ -36,15 +36,15 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)dayobjs.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)dayobjs.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: dayobjs.c,v 1.4 1998/09/13 01:30:31 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: dayobjs.c,v 1.5 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ #include "extern.h" -struct objs dayobjs[] = { +const struct objs dayobjs[] = { { 236, HORSE }, { 237, CAR }, { 275, POT }, @@ -141,5 +141,5 @@ struct objs dayobjs[] = { { 130, BRACELET }, { 93, GIRL }, { 268, LAMPON }, - { 0 } + { 0, 0 } }; diff --git a/games/battlestar/extern.h b/games/battlestar/extern.h index c5b976bafe8..1508384351d 100644 --- a/games/battlestar/extern.h +++ b/games/battlestar/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.4 1998/09/13 01:30:32 pjanzen Exp $ */ +/* $OpenBSD: extern.h,v 1.5 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: extern.h,v 1.5 1995/04/24 12:22:18 cgd Exp $ */ /* @@ -36,6 +36,7 @@ * @(#)extern.h 8.1 (Berkeley) 5/31/93 */ +#include <sys/param.h> #include <sys/time.h> #include <ctype.h> @@ -54,9 +55,10 @@ #define OUTSIDE (position > 68 && position < 246 && position != 218) #define rnd(x) (random() % (x)) #define max(a,b) ((a) < (b) ? (b) : (a)) -#define testbit(array, index) (array[index/BITS] & (1 << (index % BITS))) -#define setbit(array, index) (array[index/BITS] |= (1 << (index % BITS))) -#define clearbit(array, index) (array[index/BITS] &= ~(1 << (index % BITS))) + /* avoid name collision with sys/param.h */ +#define TestBit(array, index) (array[index/BITS] & (1 << (index % BITS))) +#define SetBit(array, index) (array[index/BITS] |= (1 << (index % BITS))) +#define ClearBit(array, index) (array[index/BITS] &= ~(1 << (index % BITS))) /* well known rooms */ #define FINAL 275 @@ -226,7 +228,7 @@ #define MAXCUMBER 10 struct room { - char *name; + const char *name; int link[8]; #define north link[0] #define south link[1] @@ -236,81 +238,81 @@ struct room { #define access link[5] #define down link[6] #define flyhere link[7] - char *desc; + const char *desc; unsigned int objects[NUMOFWORDS]; }; extern struct room dayfile[]; extern struct room nightfile[]; -struct room *location; +extern struct room *location; /* object characteristics */ -extern char *objdes[NUMOFOBJECTS]; -extern char *objsht[NUMOFOBJECTS]; -extern char *ouch[NUMOFINJURIES]; -extern int objwt[NUMOFOBJECTS]; -extern int objcumber[NUMOFOBJECTS]; +extern const char *const objdes[NUMOFOBJECTS]; +extern const char *const objsht[NUMOFOBJECTS]; +extern const char *const ouch[NUMOFINJURIES]; +extern const int objwt[NUMOFOBJECTS]; +extern const int objcumber[NUMOFOBJECTS]; /* current input line */ #define NWORD 20 /* words per line */ -char words[NWORD][15]; -int wordvalue[NWORD]; -int wordtype[NWORD]; -int wordcount, wordnumber; +extern char words[NWORD][15]; +extern int wordvalue[NWORD]; +extern int wordtype[NWORD]; +extern int wordcount, wordnumber; /* state of the game */ -time_t ourtime; -int position; -int direction; -int left, right, ahead, back; -int ourclock, fuel, torps; -int carrying, encumber; -int rythmn; +extern time_t ourtime; +extern int position; +extern int direction; +extern int left, right, ahead, back; +extern int ourclock, fuel, torps; +extern int carrying, encumber; +extern int rythmn; extern int followfight; -int ate; -int snooze; -int meetgirl; +extern int ate; +extern int snooze; +extern int meetgirl; extern int followgod; -int godready; +extern int godready; extern int win; -int wintime; -int wiz; -int tempwiz; -int matchlight; +extern int wintime; +extern int wiz; +extern int tempwiz; +extern int matchlight; extern int matchcount; -int loved; -int pleasure, power, ego; +extern int loved; +extern int pleasure, power, ego; extern int WEIGHT; extern int CUMBER; -int notes[NUMOFNOTES]; -unsigned int inven[NUMOFWORDS]; -unsigned int wear[NUMOFWORDS]; -char beenthere[NUMOFROOMS+1]; -char injuries[NUMOFINJURIES]; +extern int notes[NUMOFNOTES]; +extern unsigned int inven[NUMOFWORDS]; +extern unsigned int wear[NUMOFWORDS]; +extern char beenthere[NUMOFROOMS+1]; +extern char injuries[NUMOFINJURIES]; -char uname[9]; +extern char username[LOGIN_NAME_MAX + 1]; struct wlist { - char *string; + const char *string; int value, article; struct wlist *next; }; #define HASHSIZE 256 #define HASHMUL 81 #define HASHMASK (HASHSIZE - 1) -struct wlist *hashtab[HASHSIZE]; +extern struct wlist *hashtab[HASHSIZE]; extern struct wlist wlist[]; struct objs { short room; short obj; }; -extern struct objs dayobjs[]; -extern struct objs nightobjs[]; +extern const struct objs dayobjs[]; +extern const struct objs nightobjs[]; void blast __P((void)); void bury __P((void)); -int card __P((char *, int)); -int checkout __P((char *)); +int card __P((const char *, int)); +int checkout __P((const char *)); void chime __P((void)); void convert __P((int)); void crash __P((void)); @@ -320,17 +322,17 @@ void dig __P((void)); int draw __P((void)); void drink __P((void)); int drive __P((void)); -int drop __P((char *)); +int drop __P((const char *)); int eat __P((void)); void endfly __P((void)); int fight __P((int, int)); int follow __P((void)); -char *getcom __P((char *, int, char *, char *)); +char *getcom __P((char *, int, const char *, const char *)); char *getword __P((char *, char *, int)); void getutmp __P((char *)); int give __P((void)); -int hash __P((char *)); -void initialize __P((char)); +int hash __P((const char *)); +void initialize __P((const char *)); void install __P((struct wlist *)); int jump __P((void)); void kiss __P((void)); @@ -338,7 +340,7 @@ int land __P((void)); int launch __P((void)); void light __P((void)); void live __P((void)); -struct wlist *lookup __P((char *)); +struct wlist *lookup __P((const char *)); void love __P((void)); int move __P((int, int)); void moveenemy __P((int)); @@ -346,32 +348,32 @@ void murder __P((void)); void news __P((void)); void newway __P((int)); void notarget __P((void)); +void open_score_file __P((void)); void parse __P((void)); void post __P((char)); void printobjs __P((void)); int put __P((void)); int puton __P((void)); -char *rate __P((void)); +const char *rate __P((void)); void ravage __P((void)); -void restore __P((void)); +void restore __P((const char *)); int ride __P((void)); -void save __P((void)); +void save __P((const char *)); +char *save_file_name __P((const char *, size_t)); void screen __P((void)); int shoot __P((void)); void succumb __P((int)); int take __P((unsigned int[])); int takeoff __P((void)); void target __P((void)); -int throw __P((char *)); -char *truedirec __P((int, char)); -int ucard __P((unsigned int *)); +int throw __P((const char *)); +const char *truedirec __P((int, char)); +int ucard __P((const unsigned int *)); int use __P((void)); int visual __P((void)); int wearit __P((void)); void whichway __P((struct room)); -int wizard __P((char *)); +int wizard __P((const char *)); void wordinit __P((void)); void writedes __P((void)); int zzz __P((void)); - -gid_t egid; diff --git a/games/battlestar/fly.c b/games/battlestar/fly.c index b40034b1da3..1454dc416c0 100644 --- a/games/battlestar/fly.c +++ b/games/battlestar/fly.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fly.c,v 1.6 1998/09/13 01:30:32 pjanzen Exp $ */ +/* $OpenBSD: fly.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: fly.c,v 1.3 1995/03/21 15:07:28 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)fly.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)fly.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: fly.c,v 1.6 1998/09/13 01:30:32 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: fly.c,v 1.7 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ diff --git a/games/battlestar/getcom.c b/games/battlestar/getcom.c index 5a25a42c5c2..2801fe4a89b 100644 --- a/games/battlestar/getcom.c +++ b/games/battlestar/getcom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getcom.c,v 1.5 1998/09/13 01:30:32 pjanzen Exp $ */ +/* $OpenBSD: getcom.c,v 1.6 1999/09/25 20:30:45 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.5 1998/09/13 01:30:32 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: getcom.c,v 1.6 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -48,7 +48,7 @@ char * getcom(buf, size, prompt, error) char *buf; int size; - char *prompt, *error; + const char *prompt, *error; { for (;;) { fputs(prompt, stdout); diff --git a/games/battlestar/globals.c b/games/battlestar/globals.c index 7e0edec8195..6957c4c5932 100644 --- a/games/battlestar/globals.c +++ b/games/battlestar/globals.c @@ -1,4 +1,4 @@ -/* $OpenBSD: globals.c,v 1.4 1998/09/13 01:30:32 pjanzen Exp $ */ +/* $OpenBSD: globals.c,v 1.5 1999/09/25 20:30:45 pjanzen Exp $ */ /* $NetBSD: globals.c,v 1.3 1995/03/21 15:07:32 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)globals.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)globals.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: globals.c,v 1.4 1998/09/13 01:30:32 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: globals.c,v 1.5 1999/09/25 20:30:45 pjanzen Exp $"; #endif #endif /* not lint */ @@ -47,7 +47,7 @@ static char rcsid[] = "$OpenBSD: globals.c,v 1.4 1998/09/13 01:30:32 pjanzen Exp int WEIGHT = MAXWEIGHT; int CUMBER = MAXCUMBER; -char *objdes[NUMOFOBJECTS] = { +const char *const objdes[NUMOFOBJECTS] = { "There is a knife here", "There are an exquisitely crafted sword and scabbard here.", 0, /* can land from here */ @@ -115,7 +115,7 @@ char *objdes[NUMOFOBJECTS] = { }; -char *objsht[NUMOFOBJECTS] = { +const char *const objsht[NUMOFOBJECTS] = { "knife", "fine sword", 0, @@ -182,7 +182,7 @@ char *objsht[NUMOFOBJECTS] = { "diamond block" }; -char *ouch[NUMOFINJURIES] = { +const char *const ouch[NUMOFINJURIES] = { "some minor abrasions", "some minor lacerations", "a minor puncture wound", @@ -198,7 +198,7 @@ char *ouch[NUMOFINJURIES] = { "a broken neck" }; -int objwt[NUMOFOBJECTS] = { +const int objwt[NUMOFOBJECTS] = { 1, 5, 0, 10, 15, 2, 10, 10, 3, 5, 50, 2500, 2, 1, 100, 1, 2, 1, 1, 1, 60, 10, 5, 0, @@ -209,7 +209,7 @@ int objwt[NUMOFOBJECTS] = { 50, 45, 45, 100, 2000, 30, 20, 10 }; -int objcumber[NUMOFOBJECTS] = { +const int objcumber[NUMOFOBJECTS] = { 1, 5, 0, 150, 10, 1, 5, 2, 2, 1, 5, 10, 1, 1, 10, 1, 1, 1, 1, 1, 7, 5, 4, 0, @@ -224,3 +224,39 @@ int win = 1; int matchcount = 20; int followgod = -1; int followfight = -1; + +struct room *location; + + /* current input line */ +char words[NWORD][15]; +int wordvalue[NWORD]; +int wordtype[NWORD]; +int wordcount, wordnumber; + + /* state of the game */ +int ourtime; +int position; +int direction; +int left, right, ahead, back; +int fuel, torps; +int carrying, encumber; +int rythmn; +int ate; +int snooze; +int meetgirl; +int godready; +int wintime; +int wiz; +int tempwiz; +int matchlight; +int loved; +int pleasure, power, ego; +int notes[NUMOFNOTES]; +unsigned int inven[NUMOFWORDS]; +unsigned int wear[NUMOFWORDS]; +char beenthere[NUMOFROOMS + 1]; +char injuries[NUMOFINJURIES]; + +char username[LOGIN_NAME_MAX + 1]; + +struct wlist *hashtab[HASHSIZE]; diff --git a/games/battlestar/init.c b/games/battlestar/init.c index 73cfcc3fc6f..ce87433e9fa 100644 --- a/games/battlestar/init.c +++ b/games/battlestar/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.5 1998/09/13 01:30:32 pjanzen Exp $ */ +/* $OpenBSD: init.c,v 1.6 1999/09/25 20:30:46 pjanzen Exp $ */ /* $NetBSD: init.c,v 1.4 1995/03/21 15:07:35 cgd Exp $ */ /* @@ -36,54 +36,58 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)init.c 8.4 (Berkeley) 4/30/95"; #else -static char rcsid[] = "$OpenBSD: init.c,v 1.5 1998/09/13 01:30:32 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: init.c,v 1.6 1999/09/25 20:30:46 pjanzen Exp $"; #endif #endif /* not lint */ #include "extern.h" void -initialize(startup) - char startup; +initialize(filename) + const char *filename; { - struct objs *p; + const struct objs *p; + char *savefile; puts("Version 4.2, fall 1984."); puts("First Adventure game written by His Lordship, the honorable"); puts("Admiral D.W. Riggle\n"); location = dayfile; srandom(getpid()); - getutmp(uname); + getutmp(username); wordinit(); - if (startup) { + if (filename == NULL) { direction = NORTH; ourtime = 0; snooze = CYCLE * 1.5; position = 22; - setbit(wear, PAJAMAS); + SetBit(wear, PAJAMAS); fuel = TANKFULL; torps = TORPEDOES; for (p = dayobjs; p->room != 0; p++) - setbit(location[p->room].objects, p->obj); - } else - restore(); - wiz = wizard(uname); + SetBit(location[p->room].objects, p->obj); + } else { + savefile = save_file_name(filename, strlen(filename)); + restore(savefile); + free(savefile); + } + wiz = wizard(username); signal(SIGINT, die); } void -getutmp(uname) - char *uname; +getutmp(username) + char *username; { struct passwd *ptr; ptr = getpwuid(getuid()); - strcpy(uname, ptr ? ptr->pw_name : ""); + strcpy(username, ptr ? ptr->pw_name : ""); } -char *list[] = { /* hereditary wizards */ +const char *const list[] = { /* hereditary wizards */ "riggle", "chris", "edward", @@ -94,7 +98,7 @@ char *list[] = { /* hereditary wizards */ 0 }; -char *badguys[] = { +const char *const badguys[] = { "wnj", "root", "ted", @@ -102,37 +106,37 @@ char *badguys[] = { }; int -wizard(uname) - char *uname; +wizard(username) + const char *username; { int flag; - if ((flag = checkout(uname)) != 0) - printf("You are the Great wizard %s.\n", uname); + if ((flag = checkout(username)) != 0) + printf("You are the Great wizard %s.\n", username); return flag; } int -checkout(uname) - char *uname; +checkout(username) + const char *username; { - char **ptr; + const char *const *ptr; for (ptr = list; *ptr; ptr++) - if (strcmp(*ptr, uname) == 0) + if (strcmp(*ptr, username) == 0) return 1; for (ptr = badguys; *ptr; ptr++) - if (strcmp(*ptr, uname) == 0) { + if (strcmp(*ptr, username) == 0) { printf("You are the Poor anti-wizard %s. Good Luck!\n", - uname); + username); if (location != NULL) { CUMBER = 3; WEIGHT = 9; /* that'll get him! */ ourclock = 10; - setbit(location[7].objects, WOODSMAN); /* viper room */ - setbit(location[20].objects, WOODSMAN); /* laser " */ - setbit(location[13].objects, DARK); /* amulet " */ - setbit(location[8].objects, ELF); /* closet */ + SetBit(location[7].objects, WOODSMAN); /* viper room */ + SetBit(location[20].objects, WOODSMAN); /* laser " */ + SetBit(location[13].objects, DARK); /* amulet " */ + SetBit(location[8].objects, ELF); /* closet */ } return 0; /* anything else, Chris? */ } diff --git a/games/battlestar/misc.c b/games/battlestar/misc.c index 8b933850b32..fc15adc3338 100644 --- a/games/battlestar/misc.c +++ b/games/battlestar/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.4 1998/09/13 01:30:32 pjanzen Exp $ */ +/* $OpenBSD: misc.c,v 1.5 1999/09/25 20:30:46 pjanzen Exp $ */ /* $NetBSD: misc.c,v 1.3 1995/03/21 15:07:37 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)misc.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: misc.c,v 1.4 1998/09/13 01:30:32 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.5 1999/09/25 20:30:46 pjanzen Exp $"; #endif #endif /* not lint */ @@ -46,10 +46,10 @@ static char rcsid[] = "$OpenBSD: misc.c,v 1.4 1998/09/13 01:30:32 pjanzen Exp $" int card(array, size) /* for beenthere, injuries */ - char *array; + const char *array; int size; { - char *end = array + size; + const char *end = array + size; int i = 0; while (array < end) @@ -60,12 +60,12 @@ card(array, size) /* for beenthere, injuries */ int ucard(array) - unsigned int *array; + const unsigned int *array; { int j = 0, n; for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(array, n)) + if (TestBit(array, n)) j++; return (j); } diff --git a/games/battlestar/nightfile.c b/games/battlestar/nightfile.c index 8d5b2619c76..e15af6bbd75 100644 --- a/games/battlestar/nightfile.c +++ b/games/battlestar/nightfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nightfile.c,v 1.5 1999/07/31 18:11:26 pjanzen Exp $ */ +/* $OpenBSD: nightfile.c,v 1.6 1999/09/25 20:30:46 pjanzen Exp $ */ /* $NetBSD: nightfile.c,v 1.3 1995/03/21 15:07:41 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)nightfile.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)nightfile.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: nightfile.c,v 1.5 1999/07/31 18:11:26 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: nightfile.c,v 1.6 1999/09/25 20:30:46 pjanzen Exp $"; #endif #endif /* not lint */ diff --git a/games/battlestar/nightobjs.c b/games/battlestar/nightobjs.c index 4243a6b1b13..0a6ec54f434 100644 --- a/games/battlestar/nightobjs.c +++ b/games/battlestar/nightobjs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nightobjs.c,v 1.4 1998/09/13 01:30:33 pjanzen Exp $ */ +/* $OpenBSD: nightobjs.c,v 1.5 1999/09/25 20:30:46 pjanzen Exp $ */ /* $NetBSD: nightobjs.c,v 1.3 1995/03/21 15:07:46 cgd Exp $ */ /* @@ -36,15 +36,15 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)nightobjs.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)nightobjs.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: nightobjs.c,v 1.4 1998/09/13 01:30:33 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: nightobjs.c,v 1.5 1999/09/25 20:30:46 pjanzen Exp $"; #endif #endif /* not lint */ #include "extern.h" -struct objs nightobjs[] = { +const struct objs nightobjs[] = { { 218, PAJAMAS }, { 235, NATIVE }, { 92, PAPAYAS }, @@ -103,5 +103,5 @@ struct objs nightobjs[] = { { 249, FOOT }, { 250, FOOT }, { 93, PAPAYAS }, - { 0 } + { 0, 0 } }; diff --git a/games/battlestar/parse.c b/games/battlestar/parse.c index 3d39c239924..a927124e5cd 100644 --- a/games/battlestar/parse.c +++ b/games/battlestar/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.5 1998/09/13 01:30:33 pjanzen Exp $ */ +/* $OpenBSD: parse.c,v 1.6 1999/09/25 20:30:46 pjanzen Exp $ */ /* $NetBSD: parse.c,v 1.3 1995/03/21 15:07:48 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)parse.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: parse.c,v 1.5 1998/09/13 01:30:33 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: parse.c,v 1.6 1999/09/25 20:30:46 pjanzen Exp $"; #endif #endif /* not lint */ @@ -55,7 +55,7 @@ wordinit() int hash(s) - char *s; + const char *s; { int hashval = 0; @@ -69,7 +69,7 @@ hash(s) struct wlist * lookup(s) - char *s; + const char *s; { struct wlist *wp; diff --git a/games/battlestar/pathnames.h b/games/battlestar/pathnames.h index 2baf0912492..f8ac0e7bd19 100644 --- a/games/battlestar/pathnames.h +++ b/games/battlestar/pathnames.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pathnames.h,v 1.2 1997/06/30 19:56:40 kstailey Exp $ */ +/* $OpenBSD: pathnames.h,v 1.3 1999/09/25 20:30:46 pjanzen Exp $ */ /* $NetBSD: pathnames.h,v 1.3 1995/03/21 15:07:51 cgd Exp $ */ /*- @@ -37,3 +37,4 @@ */ #define _PATH_SCORE "/var/games/battlestar.log" +#define DEFAULT_SAVE_FILE "Bstar" diff --git a/games/battlestar/room.c b/games/battlestar/room.c index 94467523bd4..0b11089b60e 100644 --- a/games/battlestar/room.c +++ b/games/battlestar/room.c @@ -1,4 +1,4 @@ -/* $OpenBSD: room.c,v 1.4 1998/09/13 01:30:33 pjanzen Exp $ */ +/* $OpenBSD: room.c,v 1.5 1999/09/25 20:30:46 pjanzen Exp $ */ /* $NetBSD: room.c,v 1.3 1995/03/21 15:07:54 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)room.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)room.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: room.c,v 1.4 1998/09/13 01:30:33 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: room.c,v 1.5 1999/09/25 20:30:46 pjanzen Exp $"; #endif #endif /* not lint */ @@ -48,13 +48,13 @@ void writedes() { int compass; - char *p; + const char *p; int c; printf("\n\t%s\n", location[position].name); if (beenthere[position] < 3) { compass = NORTH; - for (p = location[position].desc; (c = *p++);) + for (p = location[position].desc; (c = *p++) != 0;) if (c != '-' && c != '*' && c != '+') putchar(c); else { @@ -73,7 +73,7 @@ printobjs() printf("\n"); for (n = 0; n < NUMOFOBJECTS; n++) - if (testbit(p, n) && objdes[n]) + if (TestBit(p, n) && objdes[n]) puts(objdes[n]); } @@ -114,7 +114,7 @@ whichway(here) } } -char * +const char * truedirec(way, option) int way; char option; diff --git a/games/battlestar/save.c b/games/battlestar/save.c index b5a3b623937..a977815eac2 100644 --- a/games/battlestar/save.c +++ b/games/battlestar/save.c @@ -1,4 +1,4 @@ -/* $OpenBSD: save.c,v 1.7 1998/09/13 01:30:33 pjanzen Exp $ */ +/* $OpenBSD: save.c,v 1.8 1999/09/25 20:30:46 pjanzen Exp $ */ /* $NetBSD: save.c,v 1.3 1995/03/21 15:07:57 cgd Exp $ */ /* @@ -36,35 +36,26 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)save.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: save.c,v 1.7 1998/09/13 01:30:33 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: save.c,v 1.8 1999/09/25 20:30:46 pjanzen Exp $"; #endif #endif /* not lint */ #include "extern.h" void -restore() +restore(filename) + const char *filename; { - char *home; - char home1[PATH_MAX]; int n; int tmp; FILE *fp; - home = getenv("HOME"); - if (strlen(home) + 6 < sizeof(home1)) { - strcpy(home1, home); - strcat(home1, "/Bstar"); - } else { - fprintf(stderr, "%s: %s\n", home1, strerror(ENAMETOOLONG)); - return; - } - if ((fp = fopen(home1, "r")) == NULL) { - err(1, "can't open %s for reading", home1); - return; - } + if (filename == NULL) + exit(1); /* Error determining save file name. */ + if ((fp = fopen(filename, "r")) == NULL) + err(1, "can't open %s for reading", filename); fread(&WEIGHT, sizeof WEIGHT, 1, fp); fread(&CUMBER, sizeof CUMBER, 1, fp); fread(&ourclock, sizeof ourclock, 1, fp); @@ -101,32 +92,24 @@ restore() fread(&power, sizeof power, 1, fp); /* Check the final read in case file was truncated */ if (fread(&ego, sizeof ego, 1, fp) < 1) - errx(1, "save file %s is truncated", home1); + errx(1, "save file %s is truncated", filename); fclose(fp); } void -save() +save(filename) + const char *filename; { - char *home; - char home1[PATH_MAX]; int n; int tmp; FILE *fp; - home = getenv("HOME"); - if (strlen(home) + 6 < sizeof(home1)) { - strcpy(home1, home); - strcat(home1, "/Bstar"); - } else { - fprintf(stderr, "%s/Bstar: %s\n", home, strerror(ENAMETOOLONG)); - return; - } - if ((fp = fopen(home1, "w")) == NULL) { - warn("can't open %s for writing", home1); + if (filename == NULL) + return; /* Error determining save file name. */ + if ((fp = fopen(filename, "w")) == NULL) { + warn("can't open %s for writing", filename); return; } - printf("Saved in %s.\n", home1); fwrite(&WEIGHT, sizeof WEIGHT, 1, fp); fwrite(&CUMBER, sizeof CUMBER, 1, fp); fwrite(&ourclock, sizeof ourclock, 1, fp); @@ -164,6 +147,53 @@ save() fwrite(&ego, sizeof ego, 1, fp); fflush(fp); if (ferror(fp)) - warn("fwrite %s", home1); + warn("fwrite %s", filename); + else + printf("Saved in %s.\n", filename); fclose(fp); } + +/* + * Given a save file name (possibly from fgetln, so without terminating NUL), + * determine the name of the file to be saved to by adding the HOME + * directory if the name does not contain a slash. Name will be allocated + * with malloc(3). + */ +char * +save_file_name(filename, len) + const char *filename; + size_t len; +{ + char *home; + char *newname; + size_t tmpl; + + if (memchr(filename, '/', len)) { + if ((newname = (char *)malloc(len + 1)) == NULL) { + warnx("out of memory"); + return NULL; + } + memcpy(newname, filename, len); + newname[len] = 0; + } else { + if ((home = getenv("HOME")) != NULL) { + tmpl = strlen(home); + if ((newname = (char *)malloc(tmpl + len + 2)) == NULL) { + warnx("out of memory"); + return NULL; + } + memcpy(newname, home, tmpl); + newname[tmpl] = '/'; + memcpy(newname + tmpl + 1, filename, len); + newname[tmpl + len + 1] = 0; + } else { + if ((newname = (char *)malloc(len + 1)) == NULL) { + warnx("out of memory"); + return NULL; + } + memcpy(newname, filename, len); + newname[len] = 0; + } + } + return(newname); +} diff --git a/games/battlestar/words.c b/games/battlestar/words.c index 7ed4bec783f..d10ce59eba3 100644 --- a/games/battlestar/words.c +++ b/games/battlestar/words.c @@ -1,4 +1,4 @@ -/* $OpenBSD: words.c,v 1.4 1998/09/13 01:30:34 pjanzen Exp $ */ +/* $OpenBSD: words.c,v 1.5 1999/09/25 20:30:46 pjanzen Exp $ */ /* $NetBSD: words.c,v 1.3 1995/03/21 15:08:00 cgd Exp $ */ /* @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)words.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)words.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: words.c,v 1.4 1998/09/13 01:30:34 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: words.c,v 1.5 1999/09/25 20:30:46 pjanzen Exp $"; #endif #endif /* not lint */ |