Battlestar (Part 3 of 5)
Peter E. Yee
yee at ucbvax.ARPA
Thu Jan 24 14:25:21 AEST 1985
This is part 3 of the BATTLESTAR distribution.
# This is a shell archive.
# Remove everything above and including the cut line.
# Then run the rest of the file through sh.
-----cut here-----cut here-----cut here-----cut here-----
#!/bin/sh
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# battlestar/externs.h
# battlestar/dayobjs
# battlestar/nightobjs
# battlestar/Makefile
# battlestar/cypher.c
# battlestar/fly.c
# battlestar/getcom.c
# battlestar/battlestar.6
# battlestar/battlestar.c
# battlestar/globals.c
# battlestar/init.c
# battlestar/mkfile.c
# battlestar/mkobjs.c
# battlestar/mkwlist.c
# This archive created: Wed Jan 23 20:04:05 1985
cat << \SHAR_EOF > battlestar/externs.h
/* @(#)externs.h 1.2 11/28/84 */
#include <sys/signal.h>
#include <stdio.h>
#define PATH(x) "/usr/games/lib/x"
#define logfile PATH(battlestar.log)
#define BITS (8 * sizeof (int))
#define OUTSIDE (position > 68 && position < 246 && position != 218)
#define rnd(x) (rand() % (x))
#define max(a,b) ((a) < (b) ? (b) : (a))
#define testbit(array, index) (array[index/BITS] & (1 << (index % BITS)))
#define setbit(array, index) (array[index/BITS] |= (1 << (index % BITS)))
#define clearbit(array, index) (array[index/BITS] &= ~(1 << (index % BITS)))
/* well known rooms */
#define FINAL 275
#define GARDEN 197
#define POOLS 126
#define DOCK 93
/* word types */
#define VERB 0
#define OBJECT 1
#define NOUNS 2
#define PREPS 3
#define ADJS 4
#define CONJ 5
/* words numbers */
#define KNIFE 0
#define SWORD 1
#define LAND 2
#define WOODSMAN 3
#define TWO_HANDED 4
#define CLEAVER 5
#define BROAD 6
#define MAIL 7
#define HELM 8
#define SHIELD 9
#define MAID 10
#define BODY 10
#define VIPER 11
#define LAMPON 12
#define SHOES 13
#define CYLON 14
#define PAJAMAS 15
#define ROBE 16
#define AMULET 17
#define MEDALION 18
#define TALISMAN 19
#define DEADWOOD 20
#define MALLET 21
#define LASER 22
#define BATHGOD 23
#define NORMGOD 24
#define GRENADE 25
#define CHAIN 26
#define ROPE 27
#define LEVIS 28
#define MACE 29
#define SHOVEL 30
#define HALBERD 31
#define COMPASS 32
#define CRASH 33
#define ELF 34
#define FOOT 35
#define COINS 36
#define MATCHES 37
#define MAN 38
#define PAPAYAS 39
#define PINEAPPLE 40
#define KIWI 41
#define COCONUTS 42
#define MANGO 43
#define RING 44
#define POTION 45
#define BRACELET 46
#define GIRL 47
#define GIRLTALK 48
#define DARK 49
#define TIMER 50
#define CHAR 53
#define BOMB 54
#define DEADGOD 55
#define DEADTIME 56
#define DEADNATIVE 57
#define NATIVE 58
#define HORSE 59
#define CAR 60
#define POT 61
#define BAR 62
#define BLOCK 63
#define NUMOFOBJECTS 64
/* non-objects below */
#define UP 1000
#define DOWN 1001
#define AHEAD 1002
#define BACK 1003
#define RIGHT 1004
#define LEFT 1005
#define TAKE 1006
#define USE 1007
#define LOOK 1008
#define QUIT 1009
#define NORTH 1010
#define SOUTH 1011
#define EAST 1012
#define WEST 1013
#define SU 1014
#define DROP 1015
#define TAKEOFF 1016
#define DRAW 1017
#define PUTON 1018
#define WEARIT 1019
#define PUT 1020
#define INVEN 1021
#define EVERYTHING 1022
#define AND 1023
#define KILL 1024
#define RAVAGE 1025
#define UNDRESS 1026
#define THROW 1027
#define LAUNCH 1028
#define LANDIT 1029
#define LIGHT 1030
#define FOLLOW 1031
#define KISS 1032
#define LOVE 1033
#define GIVE 1034
#define SMITE 1035
#define SHOOT 1036
#define ON 1037
#define OFF 1038
#define TIME 1039
#define SLEEP 1040
#define DIG 1041
#define EAT 1042
#define SWIM 1043
#define DRINK 1044
#define DOOR 1045
#define SAVE 1046
#define RIDE 1047
#define DRIVE 1048
#define SCORE 1049
#define BURY 1050
#define JUMP 1051
#define KICK 1052
/* injuries */
#define ARM 6 /* broken arm */
#define RIBS 7 /* broken ribs */
#define SPINE 9 /* broken back */
#define SKULL 11 /* fractured skull */
#define INCISE 10 /* deep incisions */
#define NECK 12 /* broken NECK */
#define NUMOFINJURIES 13
/* notes */
#define CANTLAUNCH 0
#define LAUNCHED 1
#define CANTSEE 2
#define CANTMOVE 3
#define JINXED 4
#define DUG 5
#define NUMOFNOTES 6
/* fundamental constants */
#define NUMOFROOMS 275
#define NUMOFWORDS ((NUMOFOBJECTS + BITS - 1) / BITS)
#define LINELENGTH 81
#define TODAY 0
#define TONIGHT 1
#define CYCLE 100
/* initial variable values */
#define TANKFULL 250
#define TORPEDOES 10
#define MAXWEIGHT 60
#define MAXCUMBER 10
struct room {
char *name;
int link[8];
#define north link[0]
#define south link[1]
#define east link[2]
#define west link[3]
#define up link[4]
#define access link[5]
#define down link[6]
#define flyhere link[7]
char *desc;
unsigned int objects[NUMOFWORDS];
};
struct room dayfile[];
struct room nightfile[];
struct room *location;
/* object characteristics */
char *objdes[NUMOFOBJECTS];
char *objsht[NUMOFOBJECTS];
char *ouch[NUMOFINJURIES];
int objwt[NUMOFOBJECTS];
int objcumber[NUMOFOBJECTS];
/* current input line */
#define NWORD 20 /* words per line */
char words[NWORD][15];
int wordvalue[NWORD];
int wordtype[NWORD];
int wordcount, wordnumber;
char *truedirec(), *rate();
char *getcom(), *getword();
/* state of the game */
int time;
int position;
int direction;
int left, right, ahead, back;
int clock, fuel, torps;
int carrying, encumber;
int rythmn;
int followfight;
int ate;
int snooze;
int meetgirl;
int followgod;
int godready;
int win;
int wintime;
int wiz;
int tempwiz;
int matchlight, matchcount;
int loved;
int pleasure, power, ego;
int WEIGHT;
int CUMBER;
int notes[NUMOFNOTES];
unsigned int inven[NUMOFWORDS];
unsigned int wear[NUMOFWORDS];
char beenthere[NUMOFROOMS+1];
char injuries[NUMOFINJURIES];
char uname[9];
struct wlist {
char *string;
int value, article;
struct wlist *next;
};
#define HASHSIZE 256
#define HASHMUL 81
#define HASHMASK (HASHSIZE - 1)
struct wlist *hashtab[HASHSIZE];
struct wlist wlist[];
struct objs {
short room;
short obj;
};
struct objs dayobjs[];
struct objs nightobjs[];
SHAR_EOF
if test 5227 -ne "`wc -c battlestar/externs.h`"
then
echo shar: error transmitting battlestar/externs.h '(should have been 5227 characters)'
fi
cat << \SHAR_EOF > battlestar/dayobjs
@(#)dayobjs 1.1 11/18/84
236 59
237 60
275 61
275 62
275 63
260 36
266 49
235 50
51 51
59 51
48 51
66 52
65 52
19 54
167 58
21 0
30 0
30 5
260 1
70 2
71 2
72 2
73 2
74 2
75 2
76 2
77 2
78 2
79 2
81 2
82 2
83 2
84 2
85 2
86 2
87 2
88 2
90 2
95 2
96 2
97 2
99 2
100 2
104 2
172 3
172 20
172 21
146 34
146 31
146 9
190 4
190 45
142 6
258 7
258 8
21 10
7 11
216 13
64 14
36 14
49 14
8 16
13 17
20 22
126 23
26 25
256 25
237 26
237 32
218 28
164 29
137 30
11 36
24 37
235 37
93 38
109 39
110 40
152 40
154 40
111 41
149 43
112 42
150 42
151 42
153 42
192 42
204 42
207 42
209 42
213 42
240 42
218 44
130 46
93 47
268 12
SHAR_EOF
if test 615 -ne "`wc -c battlestar/dayobjs`"
then
echo shar: error transmitting battlestar/dayobjs '(should have been 615 characters)'
fi
cat << \SHAR_EOF > battlestar/nightobjs
@(#)nightobjs 1.1 11/18/84
218 15
235 58
92 39
92 40
92 41
92 43
92 58
92 38
181 12
236 12
92 12
216 3
216 20
216 21
168 3
168 20
168 21
170 3
170 20
170 21
124 9
124 31
124 34
144 9
144 31
144 34
113 9
113 31
113 34
161 9
161 31
161 34
169 9
169 31
169 34
182 9
182 31
182 34
198 9
198 31
198 34
212 9
212 31
212 34
216 9
216 31
216 34
226 9
226 31
226 34
228 9
228 31
228 34
68 14
144 30
249 35
250 35
93 39
SHAR_EOF
if test 410 -ne "`wc -c battlestar/nightobjs`"
then
echo shar: error transmitting battlestar/nightobjs '(should have been 410 characters)'
fi
cat << \SHAR_EOF > battlestar/Makefile
# @(#)Makefile 1.3 12/3/84
CFLAGS= -O
OBJS= battlestar.o com1.o com2.o com3.o com4.o com5.o com6.o com7.o \
init.o cypher.o getcom.o parse.o room.o save.o fly.o misc.o \
globals.o \
wlist.o dayfile.o nightfile.o dayobjs.o nightobjs.o
CFILES= battlestar.c com1.c com2.c com3.c com4.c com5.c com6.c com7.c \
init.c cypher.c getcom.c parse.c room.c save.c fly.c misc.c \
globals.c
LIBS= -lcurses -ltermlib
LINTFLAGS= -h
JUNKFILES= battlestar tags mkfile mkwlist mkobjs \
wlist.c dayfile.c nightfile.c dayobjs.c nightobjs.c
DATAFILES= dayfile nightfile battlewords dayobjs nightobjs
DIR= $(DESTDIR)/usr/games
LOGFILE= $(DIR)/lib/battlestar.log
MAN= $(DESTDIR)/usr/man/man6/battlestar.6
battlestar: ${OBJS}
cc ${OBJS} ${LIBS} -o battlestar
mkfile: mkfile.c
$(CC) $(CFLAGS) -o mkfile mkfile.c
dayfile.o: dayfile mkfile
mkfile dayfile
$(CC) $(CFLAGS) -c dayfile.c
rm dayfile.c
nightfile.o: nightfile mkfile
mkfile nightfile
$(CC) $(CFLAGS) -c nightfile.c
rm nightfile.c
mkwlist: mkwlist.c
$(CC) $(CFLAGS) -o mkwlist mkwlist.c
wlist.c: battlewords mkwlist
mkwlist battlewords
mkobjs: mkobjs.c
$(CC) $(CFLAGS) -o mkobjs mkobjs.c
dayobjs.c: dayobjs mkobjs
mkobjs dayobjs
nightobjs.c: nightobjs mkobjs
mkobjs nightobjs
lint: ${CFILES}
lint ${LINTFLAGS} ${CFILES} ${LIBS}
install: battlestar $(MAN) $(LOGFILE)
install -s -c battlestar $(DIR)/battlestar
logfile $(LOGFILE):
cp /dev/null $(LOGFILE)
chmod 666 $(LOGFILE)
man $(MAN):
install -c battlestar.6 $(MAN)
clean:
rm -f ${OBJS} ${JUNKFILES}
SHAR_EOF
if test 1537 -ne "`wc -c battlestar/Makefile`"
then
echo shar: error transmitting battlestar/Makefile '(should have been 1537 characters)'
fi
cat << \SHAR_EOF > battlestar/cypher.c
#ifndef lint
static char sccsid[] = "@(#)cypher.c 1.2 11/28/84";
#endif
#include "externs.h"
cypher()
{
register int n;
int junk;
int lflag = -1;
char buffer[10];
while (wordtype[wordnumber] == ADJS)
wordnumber++;
while (wordnumber <= wordcount) {
switch(wordvalue[wordnumber]) {
case UP:
if (location[position].access || wiz || tempwiz) {
if (!location[position].access)
puts("Zap! A gust of wind lifts you up.");
if (!move(location[position].up, AHEAD))
return(-1);
} else {
puts("There is no way up");
return(-1);
}
lflag = 0;
break;
case DOWN:
if (!move(location[position].down, AHEAD))
return(-1);
lflag = 0;
break;
case LEFT:
if (!move(left, LEFT))
return(-1);
lflag = 0;
break;
case RIGHT:
if (!move(right, RIGHT))
return(-1);
lflag = 0;
break;
case AHEAD:
if (!move(ahead, AHEAD))
return(-1);
lflag = 0;
break;
case BACK:
if (!move(back, BACK))
return(-1);
lflag = 0;
break;
case SHOOT:
if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(location[position].objects,n) && *objsht[n]){
wordvalue[wordnumber+1] = n;
wordnumber = shoot();
}
wordnumber++;
wordnumber++;
}
else
shoot();
break;
case TAKE:
if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(location[position].objects,n) && *objsht[n]){
wordvalue[wordnumber+1] = n;
wordnumber = take(location[position].objects);
}
wordnumber++;
wordnumber++;
}
else
take(location[position].objects);
break;
case DROP:
if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(inven,n)){
wordvalue[wordnumber+1] = n;
wordnumber = drop("Dropped");
}
wordnumber++;
wordnumber++;
}
else
drop("Dropped");
break;
case KICK:
case THROW:
if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(inven,n) ||
testbit(location[position].objects, n) && *objsht[n]){
wordvalue[wordnumber+1] = n;
wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
}
wordnumber += 2;
} else
throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
break;
case TAKEOFF:
if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(wear,n)){
wordvalue[wordnumber+1] = n;
wordnumber = takeoff();
}
wordnumber += 2;
}
else
takeoff();
break;
case DRAW:
if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(wear,n)){
wordvalue[wordnumber+1] = n;
wordnumber = draw();
}
wordnumber += 2;
}
else
draw();
break;
case PUTON:
if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(location[position].objects,n) && *objsht[n]){
wordvalue[wordnumber+1] = n;
wordnumber = puton();
}
wordnumber += 2;
}
else
puton();
break;
case WEARIT:
if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(inven,n)){
wordvalue[wordnumber+1] = n;
wordnumber = wearit();
}
wordnumber += 2;
}
else
wearit();
break;
case EAT:
if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(inven,n)){
wordvalue[wordnumber+1] = n;
wordnumber = eat();
}
wordnumber += 2;
}
else
eat();
break;
case PUT:
put();
break;
case INVEN:
if (ucard(inven)){
puts("You are holding:\n");
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(inven,n))
printf("\t%s\n", objsht[n]);
printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."),(WEIGHT ? carrying*100/WEIGHT : -1));
printf("Your arms are %d%% full.\n",encumber*100/CUMBER);
}
else
puts("You aren't carrying anything.");
if (ucard(wear)){
puts("\nYou are wearing:\n");
for (n=0; n < NUMOFOBJECTS; n++)
if (testbit(wear,n))
printf("\t%s\n", objsht[n]);
}
else
puts("\nYou are stark naked.");
if (card(injuries,NUMOFINJURIES)){
puts("\nYou have suffered:\n");
for (n=0; n < NUMOFINJURIES; n++)
if (injuries[n])
printf("\t%s\n",ouch[n]);
printf("\nYou can still carry up to %d kilogram%s\n",WEIGHT,(WEIGHT == 1 ? "." : "s."));
}
else
puts("\nYou are in perfect health.");
break;
case USE:
lflag = use();
break;
case LOOK:
if (!notes[CANTSEE] || testbit(inven,LAMPON) || testbit(location[position].objects,LAMPON) || matchlight){
beenthere[position] = 2;
writedes();
printobjs();
if (matchlight){
puts("\nYour match splutters out.");
matchlight = 0;
}
} else
puts("I can't see anything.");
return(-1);
break;
case SU:
if (wiz || tempwiz){
printf("\nRoom (was %d) = ", position);
fgets(buffer,10,stdin);
if (*buffer != '\n')
sscanf(buffer,"%d", &position);
printf("Time (was %d) = ",time);
fgets(buffer,10,stdin);
if (*buffer != '\n')
sscanf(buffer,"%d", &time);
printf("Fuel (was %d) = ",fuel);
fgets(buffer,10,stdin);
if (*buffer != '\n')
sscanf(buffer,"%d", &fuel);
printf("Torps (was %d) = ",torps);
fgets(buffer,10,stdin);
if (*buffer != '\n')
sscanf(buffer,"%d", &torps);
printf("CUMBER (was %d) = ",CUMBER);
fgets(buffer,10,stdin);
if (*buffer != '\n')
sscanf(buffer,"%d", &CUMBER);
printf("WEIGHT (was %d) = ",WEIGHT);
fgets(buffer,10,stdin);
if (*buffer != '\n')
sscanf(buffer,"%d",&WEIGHT);
printf("Clock (was %d) = ",clock);
fgets(buffer,10,stdin);
if (*buffer != '\n')
sscanf(buffer,"%d",&clock);
printf("Wizard (was %d, %d) = ",wiz, tempwiz);
fgets(buffer,10,stdin);
if (*buffer != '\n'){
sscanf(buffer,"%d",&junk);
if (!junk)
tempwiz = wiz = 0;
}
printf("\nDONE.\n");
return(0);
}
else
puts("You aren't a wizard.");
break;
case SCORE:
printf("\tPLEASURE\tPOWER\t\tEGO\n");
printf("\t%3d\t\t%3d\t\t%3d\n\n",pleasure,power,ego);
printf("This gives you the rating of %s in %d turns.\n",rate(),time);
printf("You have visited %d out of %d rooms this run (%d%%).\n",card(beenthere,NUMOFROOMS),NUMOFROOMS,card(beenthere,NUMOFROOMS)*100/NUMOFROOMS);
break;
case KNIFE:
case KILL:
murder();
break;
case UNDRESS:
case RAVAGE:
ravage();
break;
case SAVE:
save();
break;
case FOLLOW:
lflag = follow();
break;
case GIVE:
give();
break;
case KISS:
kiss();
break;
case LOVE:
love();
break;
case RIDE:
lflag = ride();
break;
case DRIVE:
lflag = drive();
break;
case LIGHT:
light();
break;
case LAUNCH:
if (!launch())
return(-1);
else
lflag = 0;
break;
case LANDIT:
if (!land())
return(-1);
else
lflag = 0;
break;
case TIME:
chime();
break;
case SLEEP:
zzz();
break;
case DIG:
dig();
break;
case JUMP:
lflag = jump();
break;
case BURY:
bury();
break;
case SWIM:
puts("Surf's up!");
break;
case DRINK:
drink();
break;
case QUIT:
die();
default:
puts("How's that?");
return(-1);
break;
}
if (wordnumber < wordcount && *words[wordnumber++] == ',')
continue;
else return(lflag);
}
return(lflag);
}
SHAR_EOF
if test 8260 -ne "`wc -c battlestar/cypher.c`"
then
echo shar: error transmitting battlestar/cypher.c '(should have been 8260 characters)'
fi
cat << \SHAR_EOF > battlestar/fly.c
#ifndef lint
static char sccsid[] = "@(#)fly.c 1.2 11/28/84";
#endif
#include "externs.h"
#undef UP
#include <curses.h>
#define abs(a) ((a) < 0 ? -(a) : (a))
#define MIDR (LINES/2 - 1)
#define MIDC (COLS/2 - 1)
int row, column;
int dr = 0, dc = 0;
char destroyed;
int clock = 120; /* time for all the flights in the game */
char cross = 0;
int (*oldsig)();
succumb()
{
switch (oldsig) {
case SIG_DFL:
endfly();
exit(1);
case SIG_IGN:
break;
default:
endfly();
(*oldsig)();
}
}
visual()
{
int moveenemy();
destroyed = 0;
savetty();
if(initscr() == ERR){
puts("Whoops! No more memory...");
return(0);
}
oldsig = signal(SIGINT, succumb);
crmode();
noecho();
screen();
row = rnd(LINES-3) + 1;
column = rnd(COLS-2) + 1;
moveenemy();
for (;;) {
switch(getchar()){
case 'h':
case 'r':
dc = -1;
fuel--;
break;
case 'H':
case 'R':
dc = -5;
fuel -= 10;
break;
case 'l':
dc = 1;
fuel--;
break;
case 'L':
dc = 5;
fuel -= 10;
break;
case 'j':
case 'u':
dr = 1;
fuel--;
break;
case 'J':
case 'U':
dr = 5;
fuel -= 10;
break;
case 'k':
case 'd':
dr = -1;
fuel--;
break;
case 'K':
case 'D':
dr = -5;
fuel -= 10;
break;
case '+':
if (cross){
cross = 0;
notarget();
}
else
cross = 1;
break;
case ' ':
case 'f':
if (torps){
torps -= 2;
blast();
if (row == MIDR && column - MIDC < 2 && MIDC - column < 2){
destroyed = 1;
alarm(0);
}
}
else
mvaddstr(0,0,"*** Out of torpedoes. ***");
break;
case 'q':
endfly();
return(0);
default:
mvaddstr(0,26,"Commands = r,R,l,L,u,U,d,D,f,+,q");
continue;
case EOF:
break;
}
if (destroyed){
endfly();
return(1);
}
if (clock <= 0){
endfly();
die();
}
}
}
screen()
{
register int r,c,n;
int i;
clear();
i = rnd(100);
for (n=0; n < i; n++){
r = rnd(LINES-3) + 1;
c = rnd(COLS);
mvaddch(r, c, '.');
}
mvaddstr(LINES-1-1,21,"TORPEDOES FUEL TIME");
refresh();
}
target()
{
register int n;
move(MIDR,MIDC-10);
addstr("------- + -------");
for (n = MIDR-4; n < MIDR-1; n++){
mvaddch(n,MIDC,'|');
mvaddch(n+6,MIDC,'|');
}
}
notarget()
{
register int n;
move(MIDR,MIDC-10);
addstr(" ");
for (n = MIDR-4; n < MIDR-1; n++){
mvaddch(n,MIDC,' ');
mvaddch(n+6,MIDC,' ');
}
}
blast()
{
register int n;
alarm(0);
move(LINES-1, 24);
printw("%3d", torps);
for(n = LINES-1-2; n >= MIDR + 1; n--){
mvaddch(n, MIDC+MIDR-n, '/');
mvaddch(n, MIDC-MIDR+n, '\\');
refresh();
}
mvaddch(MIDR,MIDC,'*');
for(n = LINES-1-2; n >= MIDR + 1; n--){
mvaddch(n, MIDC+MIDR-n, ' ');
mvaddch(n, MIDC-MIDR+n, ' ');
refresh();
}
alarm(1);
}
moveenemy()
{
double d;
int oldr, oldc;
oldr = row;
oldc = column;
if (fuel > 0){
if (row + dr <= LINES-3 && row + dr > 0)
row += dr;
if (column + dc < COLS-1 && column + dc > 0)
column += dc;
} else if (fuel < 0){
fuel = 0;
mvaddstr(0,60,"*** Out of fuel ***");
}
d = (double) ((row - MIDR)*(row - MIDR) + (column - MIDC)*(column - MIDC));
if (d < 16){
row += (rnd(9) - 4) % (4 - abs(row - MIDR));
column += (rnd(9) - 4) % (4 - abs(column - MIDC));
}
clock--;
mvaddstr(oldr, oldc - 1, " ");
if (cross)
target();
mvaddstr(row, column - 1, "/-\\");
move(LINES-1, 24);
printw("%3d", torps);
move(LINES-1, 42);
printw("%3d", fuel);
move(LINES-1, 57);
printw("%3d", clock);
refresh();
signal(SIGALRM, moveenemy);
alarm(1);
}
endfly()
{
alarm(0);
signal(SIGALRM, SIG_DFL);
mvcur(0,COLS-1,LINES-1,0);
endwin();
signal(SIGTSTP, SIG_DFL);
signal(SIGINT, oldsig);
}
SHAR_EOF
if test 3771 -ne "`wc -c battlestar/fly.c`"
then
echo shar: error transmitting battlestar/fly.c '(should have been 3771 characters)'
fi
cat << \SHAR_EOF > battlestar/getcom.c
#ifndef lint
static char sccsid[] = "@(#)getcom.c 1.1 11/18/84";
#endif
#include <stdio.h>
#include <ctype.h>
char *
getcom(buf, size, prompt, error)
char *buf;
int size;
char *prompt, *error;
{
for (;;) {
fputs(prompt, stdout);
if (fgets(buf, size, stdin) == 0)
exit(1);
while (isspace(*buf))
buf++;
if (*buf)
break;
if (error)
puts(error);
}
return (buf);
}
char *
getword(buf1, buf2, flag)
char *buf1, *buf2;
{
/* shifts to UPPERCASE if flag > 0, lowercase if */
/* flag < 0, and leaves it unchanged if flag = 0 */
while (isspace(*buf1))
buf1++;
if (*buf1 != ',') {
if (!*buf1) {
*buf2 = 0;
return (0);
}
while (*buf1 && !isspace(*buf1) && *buf1 != ',')
*buf2++ = shift(*buf1++, flag);
} else
*buf2++ = *buf1++;
*buf2 = 0;
while (isspace(*buf1))
buf1++;
return (*buf1 ? buf1 : 0);
}
shift(c, flg)
char c;
int flg;
{
if (flg < 0)
return isupper(c) ? tolower(c) : c;
if (flg > 0)
return islower(c) ? toupper(c) : c;
return c;
}
SHAR_EOF
if test 1008 -ne "`wc -c battlestar/getcom.c`"
then
echo shar: error transmitting battlestar/getcom.c '(should have been 1008 characters)'
fi
cat << \SHAR_EOF > battlestar/battlestar.6
.. @(#)battlestar.6 1.1 11/18/84
.TH BATTLESTAR PUBLIC
.UC 4
.SH NAME
battlestar \- a tropical adventure game
.SH SYNOPSIS
.B battlestar
[
.B -r (recover a saved game)
]
.br
.fi
.SH DESCRIPTION
.I Battlestar
is an adventure game in the classic style. However, It's slightly less
of a
puzzle and more a game of exploration. There are a few magical words
in the game, but on the whole, simple English
should suffice to make one's desires understandable to the parser.
.SH "THE SETTING"
In the days before the darkness came, when battlestars ruled the
heavens...
.br
.nf
Three He made and gave them to His daughters,
Beautiful nymphs, the goddesses of the waters.
One to bring good luck and simple feats of wonder,
Two to wash the lands and churn the waves asunder,
Three to rule the world and purge the skies with thunder.
.fi
.PP
In those times great wizards were known and their powers were beyond
belief. They could take any object from thin air, and, uttering the
word
'su,' could disappear.
.PP
In those times men were known for their lust of gold and desire to
wear fine weapons. Swords and coats of mail were fashioned that could
withstand a laser blast.
.PP
But when the darkness fell, the rightful reigns were toppled. Swords
and helms and heads of state went rolling across the grass. The entire
fleet of battlestars was reduced to a single ship.
.SH "SAMPLE COMMANDS"
.nf
take --- take an object
drop --- drop an object
wear --- wear an object you are holding
draw --- carry an object you are wearing
puton --- take an object and wear it
take off -- draw an object and drop it
throw <object> <direction>
! <shell esc>
.fi
.SH "IMPLIED OBJECTS"
.nf
>-: take watermellon
watermellon:
Taken.
>-: eat
watermellon:
Eaten.
>-: take knife and sword and apple, drop all
knife:
Taken.
broadsword:
Taken.
apple:
Taken.
knife:
Dropped.
broadsword:
Dropped.
apple:
Dropped.
>-: get
knife:
Taken.
.fi
.PP
Notice that the "shadow" of the next word stays around if you
want to take advantage of it. That is, saying "take knife" and then
"drop"
will drop the knife you just took.
.SH "SCORE & INVEN"
The two commands "score" and "inven" will print out your current status
in
the game.
.SH "SAVING A GAME"
The command "save" will save your game in a file called "Bstar." You
can
recover a saved game by using the "-r" option when you start up the
game.
.SH DIRECTIONS
The compass directions N, S, E, and W can be used if you have a compass.
If you don't have a compass, you'll have to say R, L, A, or B, which
stand for
Right, Left, Ahead, and Back. Directions printed in room descriptions
are
always printed in R, L, A, & B relative directions.
.SH HISTORY
I wrote Battlestar in 1979 in order to experiment with the niceties of
the C Language.
Most interesting things that happen in the game are hardwired into the
code, so don't
send me any hate mail about it! Instead, enjoy art for art's sake!
.SH AUTHOR
David Riggle
.SH "INSPIRATION & ASSISTANCE"
Chris Guthrie
.br
Peter Da Silva
.br
Kevin Brown
.br
Edward Wang
.br
Ken Arnold & Company
.SH BUGS
Countless.
.SH "FAN MAIL"
Send to edward%ucbarpa at Berkeley.arpa, chris%ucbcory at berkeley.arpa,
riggle.pa at xerox.arpa.
SHAR_EOF
if test 3226 -ne "`wc -c battlestar/battlestar.6`"
then
echo shar: error transmitting battlestar/battlestar.6 '(should have been 3226 characters)'
fi
cat << \SHAR_EOF > battlestar/battlestar.c
#ifndef lint
static char sccsid[] = "@(#)battlestar.c 1.2 11/28/84";
#endif
#include "externs.h"
main(argc,argv)
int argc;
char **argv;
{
char mainbuf[LINELENGTH];
char *next;
initialize(argc < 2 || strcmp(argv[1], "-r"));
start:
news();
beenthere[position]++;
if (notes[LAUNCHED])
crash(); /* decrements fuel & crash */
if (matchlight) {
puts("Your match splutters out.");
matchlight = 0;
}
if (!notes[CANTSEE] || testbit(inven,LAMPON) ||
testbit(location[position].objects, LAMPON)) {
writedes();
printobjs();
} else
puts("It's too dark to see anything in here!");
whichway(location[position]);
run:
next = getcom(mainbuf, sizeof mainbuf, ">-: ",
"Please type in something.");
for (wordcount = 0; next && wordcount < 20; wordcount++)
next = getword(next, words[wordcount], -1);
parse();
switch (cypher()) {
case -1:
goto run;
case 0:
goto start;
default:
exit();
}
}
SHAR_EOF
if test 926 -ne "`wc -c battlestar/battlestar.c`"
then
echo shar: error transmitting battlestar/battlestar.c '(should have been 926 characters)'
fi
cat << \SHAR_EOF > battlestar/globals.c
#ifndef lint
static char sccsid[] = "@(#)globals.c 1.2 11/28/84";
#endif
#include "externs.h"
int WEIGHT = MAXWEIGHT;
int CUMBER = MAXCUMBER;
char *objdes[NUMOFOBJECTS] = {
"There is a knife here",
"There is an exquisitely crafted sword and scabbard here.",
0, /* can land from here */
"There is a fierce woodsman here brandishing a heavy mallet.",
"There is an unweildly two-handed sword here.",
"There is a bloody meat cleaver here.",
"A rusty broadsword is lying here.",
"There is an ancient coat of finely woven mail here.",
"There is a old dented helmet with an ostrich plume here.",
"There is a shield of some native tribe here.",
"The maid's body is lying here. She was murdered!",
"There is a Viper ready for launch here.",
"A kerosene lantern is burning luridly here.",
"An old pair of shoes has been discarded here.",
0, /* cylon */
"There is a pair of pajamas here.",
"A kingly robe of royal purple and spun gold is draped here.",
"There is a strange golden amulet on the floor here.",
"A medallion of solid gold shimmers on the ground nearby.",
"A talisman of gold is lying here.",
"A dead woodsman has fallen here. He was savagely murdered.",
"A heavy wooden mallet lies nearby.",
"There is a laser pistol here.",
"A flower-like young goddess is bathing in the hot mineral pools. She is \nwatching you, but continues to steep and sing softly.",
"The goddess is reclining on a bed of ferns and studying you intently.",
"There is a grenade here",
"There is a length of heavy chain here.",
"There is a stout rope here.",
"There is a pair of Levi's here.",
"A bloody mace is lying on the ground here.",
"There is a shovel here.",
"A long, sharp halberd is propped up here.",
"There is a compass here",
"Wreckage and smoldering debris from a crash litter the ground here.",
"A woodland Elf armed with a shield and deadly halberd lunges toward you!",
"I think I hear footsteps behind us.",
"There are a few coins here.",
"There are some matches here.",
"An unctuous man in a white suit and a dwarf are standing here.",
"There are some ripe papayas here.",
"There is a ripe pineapple here.",
"There are some kiwi fruit here.",
"There are some coconuts here.",
"There is a ripe mango here.",
"There is a sparkling diamond ring here.",
"There is a colorful pink potion in a small crystal vial here.",
"A gold bracelet is on the ground here.",
"A swarthy woman with stern features pulls you aside from the crowd,\n'I must talk to you -- but not here. Meet me at midnight in the gardens.'",
"The swarthy woman has been awaiting you anxiousy. 'I must warn you that the\nIsland has anticipated your Quest. You will not be welcomed. The Darkness is\nstrong where you must search. Seek not the shadows save only at night, for\nthen are they the weakest. In the mountains far from here a canyon winds\nwith ferns and streams and forgotten vines. There you must go. Take this\nrope.'",
"Out from the shadows a figure leaps! His black cape swirls around, and he\nholds a laser sword at your chest. 'So, you have come to fulfill the Quest.\nHa! Your weapons are no match for me!'",
"An old timer with one eye missing and no money for a drink sits at the bar.",
"You are flying through an asteroid field!",
"A planet is nearby.",
"The ground is charred here.",
"There is a thermonuclear warhead here.",
"The fragile, beautiful young goddess lies here. You murdered her horribly.",
"The old timer is lying here. He is dead.",
"The native girl's body is lying here.",
"A native girl is sitting here.",
"A gorgeous white stallion is standing here.",
"The keys are in the ignition.",
"A pot of pearls and jewels is sitting here.",
"A bar of solid gold is here.",
"There is a 10 kilogram diamond block here."
};
char *objsht[NUMOFOBJECTS] = {
"knife",
"fine sword",
0,
"Woodsman",
"two-handed sword",
"meat cleaver",
"broadsword",
"coat of mail",
"plumed helmet",
"shield",
"maid's body",
"viper",
"lantern",
"shoes",
0,
"pajamas",
"robe",
"amulet",
"medallion",
"talisman",
"woodsman's body",
"wooden mallet",
"laser",
0,
0,
"grenade",
"chain",
"rope",
"levis",
"mace",
"shovel",
"halberd",
"compass",
0,
"Elf",
0,
"coins",
"match book",
0,
"papayas",
"pineapple",
"kiwi",
"coconuts",
"mango",
"ring",
"potion",
"bracelet",
0,
0,
"Dark Lord",
0,
0,
0,
0,
"warhead",
"goddess's body",
"old timer's body",
"girl's body",
0,
"stallion",
"car",
"pot of jewels",
"bar of gold",
"diamond block"
};
char *ouch[NUMOFINJURIES] = {
"some minor abrasions",
"some minor lacerations",
"a minor puncture wound",
"a minor amputation",
"a sprained wrist",
"a fractured ankle and shattered kneecap",
"a broken arm and dislocated shoulder",
"a few broken ribs",
"a broken leg and torn ligaments",
"a broken back and ruptured spleen",
"some deep incisions and a loss of blood",
"a fractured skull and mashed face",
"a broken neck"
};
int objwt[NUMOFOBJECTS] = {
1, 5, 0, 10, 15, 2, 10, 10,
3, 5, 50, 2500, 2, 1, 100, 1,
2, 1, 1, 1, 60, 10, 5, 0,
50, 5, 15, 5, 1, 20, 10, 10,
0, 0, 0, 0, 1, 0, 0, 1,
1, 1, 2, 1, 0, 0, 0, 0,
0, 0, 100, 0, 0, 0, 55, 47,
50, 45, 45, 100, 2000, 30, 20, 10
};
int objcumber[NUMOFOBJECTS] = {
1, 5, 0, 150, 10, 1, 5, 2,
2, 1, 5, 10, 1, 1, 10, 1,
1, 1, 1, 1, 7, 5, 4, 0,
0, 1, 1, 1, 1, 5, 4, 4,
1, 0, 0, 0, 1, 0, 0, 1,
1, 1, 3, 1, 0, 0, 1, 0,
0, 0, 10, 0, 0, 0, 7, 8,
10, 8, 8, 10, 10, 3, 1, 2
};
int win = 1;
int matchcount = 20;
int followgod = -1;
int followfight = -1;
SHAR_EOF
if test 5716 -ne "`wc -c battlestar/globals.c`"
then
echo shar: error transmitting battlestar/globals.c '(should have been 5716 characters)'
fi
cat << \SHAR_EOF > battlestar/init.c
#ifndef lint
static char sccsid[] = "@(#)init.c 1.2 11/28/84";
#endif
#include "externs.h"
#include <pwd.h>
initialize(startup)
char startup;
{
register struct objs *p;
int die();
puts("Version 4.2, fall 1984.");
puts("First Adventure game written by His Lordship, the honorable");
puts("Admiral D.W. Riggle\n");
srand(getpid());
getutmp(uname);
wiz = wizard(uname);
wordinit();
if (startup) {
location = dayfile;
direction = NORTH;
time = 0;
snooze = CYCLE * 1.5;
position = 22;
setbit(wear, PAJAMAS);
fuel = TANKFULL;
torps = TORPEDOES;
for (p = dayobjs; p->room != 0; p++)
setbit(location[p->room].objects, p->obj);
} else
restore();
signal(SIGINT, die);
}
getutmp(uname)
char *uname;
{
struct passwd *ptr;
ptr = getpwuid(getuid());
strcpy(uname, ptr ? ptr->pw_name : "");
}
char *list[] = { /* hereditary wizards */
"riggle",
"chris",
"edward",
"comay",
"yee",
"dmr",
"ken",
0
};
char *badguys[] = {
"wnj",
"root",
"ted",
0
};
wizard(uname)
char *uname;
{
char flag;
if (flag = checkout(uname))
printf("You are the Great wizard %s.\n", uname);
return flag;
}
checkout(uname)
register char *uname;
{
register char **ptr;
for (ptr = list; *ptr; ptr++)
if (strcmp(*ptr, uname) == 0)
return 1;
for (ptr = badguys; *ptr; ptr++)
if (strcmp(*ptr, uname) == 0) {
printf("You are the Poor anti-wizard %s. Good Luck!\n",
uname);
CUMBER = 3;
WEIGHT = 9; /* that'll get him! */
clock = 10;
setbit(location[7].objects, WOODSMAN); /* viper room */
setbit(location[20].objects, WOODSMAN); /* laser " */
setbit(location[13].objects, DARK); /* amulet " */
setbit(location[8].objects, ELF); /* closet */
return 0; /* anything else, Chris? */
}
return 0;
}
SHAR_EOF
if test 1757 -ne "`wc -c battlestar/init.c`"
then
echo shar: error transmitting battlestar/init.c '(should have been 1757 characters)'
fi
cat << \SHAR_EOF > battlestar/mkfile.c
#ifndef lint
static char sccsid[] = "@(#)mkfile.c 1.2 11/28/84";
#endif
#include <stdio.h>
FILE *from, *to;
int line = 1;
int c;
char *unctrl();
main(argc, argv)
int argc;
char **argv;
{
register room;
char bol;
register i, j;
char temp[100];
if (argc != 2) {
printf("Usage: %s filename\n", argv[0]);
exit();
}
sprintf(temp, "%.*s.c", sizeof temp - 3, argv[1]);
if ((from = fopen(argv[1], "r")) == 0) {
perror(argv[1]);
exit(1);
}
if ((to = fopen(temp, "w")) == 0) {
perror(temp);
exit(1);
}
fprintf(to, "#include \"externs.h\"\n\n");
fprintf(to, "struct room %s[] = {\n", argv[1]);
fprintf(to, "\t{ 0 },\n");
while ((c = getc(from)) != '\n' && c != EOF)
;
for (room = 1; (i = getnum()) >= 0; room++) {
if (c != ':')
error("Format error (character '%s').", unctrl(c));
if (room != i)
error("Room number mismatch (%d should be %d).",
i, room);
while ((c = getc(from)) == ' ' || c == '\t')
;
fprintf(to, "\t{ \"");
for (; c != '\n' && c != EOF; c = getc(from)) {
if (c == '"')
putc('\\', to);
putc(c, to);
}
fprintf(to, "\",\n");
if (c == EOF)
error("Format error (character '%s').", unctrl(c));
for (i = 0; i < 8 && (j = getnum()) >= 0; i++)
fprintf(to, "%s%d", i ? ", " : "\t", j);
fprintf(to, ",\n");
if (j < 0)
error("Format error (character '%s').", unctrl(c));
for (; c == ' ' || c == '\t'; c = getc(from))
;
if (c != '\n')
error("Format error (character '%s').", unctrl(c));
bol = 0;
putc('"', to);
while ((c = getc(from)) != EOF && (c != '\n' || !bol)) {
if (bol)
fprintf(to, "\\n\\\n"), bol = 0;
if (c == '\n') {
line++;
bol = 1;
} else {
if (c == '"')
putc('\\', to);
putc(c, to);
}
}
fprintf(to, "\\n\" },\n");
}
fprintf(to, "};\n");
fclose(from);
fclose(to);
exit(0);
}
getnum()
{
register i = 0;
for (; c == '\n' || c == '\t' || c == ' '; c = getc(from))
if (c == '\n')
line++;
for (; c >= '0' && c <= '9'; c = getc(from))
i = i * 10 + c - '0';
return c == EOF ? -1 : i;
}
error(fmt, a, b, c, d)
{
printf("line %d: ", line);
printf(fmt, a, b, c, d);
exit(1);
}
char *
unctrl(c)
register c;
{
char buf[5];
if (c == EOF)
return "EOF";
c = (unsigned char) c;
if (c < ' ')
return sprintf(buf, "^%c", c + '@');
if (c < 0x7f)
return sprintf(buf, "%c", c);
if (c == 0x7f)
return "^?";
return sprintf(buf, "\\%03o", c);
}
SHAR_EOF
if test 2419 -ne "`wc -c battlestar/mkfile.c`"
then
echo shar: error transmitting battlestar/mkfile.c '(should have been 2419 characters)'
fi
cat << \SHAR_EOF > battlestar/mkobjs.c
#ifndef lint
static char sccsid[] = "@(#)mkobjs.c 1.1 11/18/84";
#endif
#include <stdio.h>
FILE *from, *to;
int line = 1;
int c;
char *unctrl();
main(argc, argv)
int argc;
char **argv;
{
register i;
char temp[100];
if (argc != 2) {
printf("Usage: %s filename\n", argv[0]);
exit();
}
sprintf(temp, "%.*s.c", sizeof temp - 3, argv[1]);
if ((from = fopen(argv[1], "r")) == 0) {
perror(argv[1]);
exit(1);
}
if ((to = fopen(temp, "w")) == 0) {
perror(temp);
exit(1);
}
fprintf(to, "#include \"externs.h\"\n\n");
fprintf(to, "struct objs %s[] = {\n", argv[1]);
while ((c = getc(from)) != '\n' && c != EOF)
;
while ((i = getnum()) >= 0) {
fprintf(to, "\t{ %d, ", i);
if ((i = getnum()) < 0)
error("Format error (character '%s').", unctrl(c));
fprintf(to, "%d },\n", i);
}
fprintf(to, "\t0\n};\n");
fclose(from);
fclose(to);
exit(0);
}
getnum()
{
register i = 0;
for (; c == '\n' || c == '\t' || c == ' '; c = getc(from))
if (c == '\n')
line++;
for (; c >= '0' && c <= '9'; c = getc(from))
i = i * 10 + c - '0';
return c == EOF ? -1 : i;
}
error(fmt, a, b, c, d)
{
printf("line %d: ", line);
printf(fmt, a, b, c, d);
exit(1);
}
char *
unctrl(c)
register c;
{
char buf[5];
if (c == EOF)
return "EOF";
c = (unsigned char) c;
if (c < ' ')
return sprintf(buf, "^%c", c + '@');
if (c < 0x7f)
return sprintf(buf, "%c", c);
if (c == 0x7f)
return "^?";
return sprintf(buf, "\\%03o", c);
}
SHAR_EOF
if test 1462 -ne "`wc -c battlestar/mkobjs.c`"
then
echo shar: error transmitting battlestar/mkobjs.c '(should have been 1462 characters)'
fi
cat << \SHAR_EOF > battlestar/mkwlist.c
#ifndef lint
static char sccsid[] = "@(#)mkwlist.c 1.1 11/18/84";
#endif
#include <stdio.h>
FILE *from, *to;
int line = 1;
int c;
char *unctrl();
main(argc, argv)
int argc;
char **argv;
{
register i, j;
if (argc != 2) {
printf("Usage: %s filename\n", argv[0]);
exit();
}
if ((from = fopen(argv[1], "r")) == 0) {
perror(argv[1]);
exit(1);
}
if ((to = fopen("wlist.c", "w")) == 0) {
perror("wlist.c");
exit(1);
}
fprintf(to, "#include \"externs.h\"\n\n");
fprintf(to, "struct wlist wlist[] = {\n");
while ((c = getc(from)) != '\n' && c != EOF)
;
if (c == '\n')
c = getc(from);
while (c != EOF) {
for (; c == ' ' || c == '\t' || c == '\n'; c = getc(from))
if (c == '\n')
line++;
if (c == EOF)
break;
fprintf(to, "\t{ \"");
for (; c != ' ' && c != '\t' && c != '\n' && c != EOF; c = getc(from))
putc(c, to);
putc('"', to);
if (c == EOF)
error("Format error (character '%s').", unctrl(c));
for (i = 0; i < 2 && (j = getnum()) >= 0; i++)
fprintf(to, ", %d", j);
fprintf(to, " },\n");
if (j < 0)
error("Format error (character '%s').", unctrl(c));
}
fprintf(to, "\t0\n};\n");
fclose(from);
fclose(to);
exit(0);
}
getnum()
{
register i = 0;
for (; c == '\n' || c == '\t' || c == ' '; c = getc(from))
if (c == '\n')
line++;
for (; c >= '0' && c <= '9'; c = getc(from))
i = i * 10 + c - '0';
return c == EOF ? -1 : i;
}
error(fmt, a, b, c, d)
{
printf("line %d: ", line);
printf(fmt, a, b, c, d);
exit(1);
}
char *
unctrl(c)
register c;
{
char buf[5];
if (c == EOF)
return "EOF";
c = (unsigned char) c;
if (c < ' ')
return sprintf(buf, "^%c", c + '@');
if (c < 0x7f)
return sprintf(buf, "%c", c);
if (c == 0x7f)
return "^?";
return sprintf(buf, "\\%03o", c);
}
SHAR_EOF
if test 1772 -ne "`wc -c battlestar/mkwlist.c`"
then
echo shar: error transmitting battlestar/mkwlist.c '(should have been 1772 characters)'
fi
# End of shell archive
exit 0
More information about the Comp.sources.unix
mailing list