Battlestar (Part 5 of 5)
Peter E. Yee
yee at ucbvax.ARPA
Thu Jan 24 14:35:53 AEST 1985
This is part 5 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/battlewords
# battlestar/com7.c
# battlestar/globals.c
# battlestar/init.c
# battlestar/misc.c
# battlestar/parse.c
# battlestar/room.c
# battlestar/save.c
# This archive created: Wed Jan 23 20:09:43 1985
cat << \SHAR_EOF > battlestar/battlewords
@(#)battlewords 1.2 11/28/84
knife 0 1
sword 1 2
scabbard 1 1
fine 1 1
two-handed 4 1
cleaver 5 1
broadsword 6 1
mail 7 1
coat 7 1
helmet 8 1
shield 9 1
maid 10 1
maid's 10 1
body 10 2
viper 11 1
lamp 12 1
lantern 12 1
shoes 13 1
pajamas 15 1
robe 16 1
amulet 17 2
medallion 18 2
talisman 19 2
woodsman 20 1
woodsman's 20 1
mallet 21 1
laser 22 1
pistol 22 1
blaster 22 1
gun 22 1
goddess 24 2
grenade 25 1
chain 26 1
rope 27 1
levis 28 1
pants 28 1
mace 29 1
shovel 30 1
halberd 31 1
compass 32 1
elf 34 1
coins 36 1
matches 37 1
match 37 1
book 37 1
man 38 2
papayas 39 1
pineapple 40 1
kiwi 41 1
coconuts 42 1
mango 43 1
ring 44 1
potion 45 1
bracelet 46 1
timer 50 2
bomb 54 1
warhead 54 1
girl 58 2
native 58 2
horse 59 1
stallion 59 1
car 60 1
volare 60 1
pot 61 1
jewels 61 1
bar 62 1
diamond 63 1
block 63 1
up 1000 0
u 1000 0
down 1001 0
d 1001 0
ahead 1002 0
a 1002 0
back 1003 0
b 1003 0
right 1004 0
r 1004 0
left 1005 0
l 1005 0
take 1006 0
get 1006 0
use 1007 0
look 1008 0
lo 1008 0
quit 1009 0
q 1009 0
su 1014 0
drop 1015 0
draw 1017 0
pull 1017 0
carry 1017 0
wear 1019 0
sheathe 1019 0
put 1020 0
buckle 1020 0
strap 1020 0
tie 1020 0
inven 1021 0
i 1021 0
everything 1022 1
all 1022 1
and 1023 5
kill 1024 0
fight 1024 0
ravage 1025 0
rape 1025 0
undress 1026 0
throw 1027 0
launch 1028 0
land 1029 0
light 1030 0
strike 1030 0
follow 1031 0
chase 1031 0
kiss 1032 0
love 1033 0
fuck 1033 0
give 1034 0
smite 1035 0
attack 1035 0
swing 1035 0
stab 1035 0
slice 1035 0
cut 1035 0
hack 1035 0
shoot 1036 0
blast 1036 0
on 1037 3
off 1038 3
time 1039 0
sleep 1040 0
dig 1041 0
eat 1042 0
swim 1043 0
drink 1044 0
door 1045 2
save 1046 0
ride 1047 0
mount 1047 0
drive 1048 0
start 1048 0
score 1049 0
points 1049 0
bury 1050 0
jump 1051 0
kick 1052 0
kerosene 0 4
plumed 0 4
ancient 0 4
golden 0 4
gold 0 4
ostrich 0 4
rusty 0 4
old 0 4
dented 0 4
blue 0 4
purple 0 4
kingly 0 4
the 0 4
climb 0 4
move 0 4
make 0 4
to 0 4
SHAR_EOF
if test 1939 -ne "`wc -c battlestar/battlewords`"
then
echo shar: error transmitting battlestar/battlewords '(should have been 1939 characters)'
fi
cat << \SHAR_EOF > battlestar/com7.c
#ifndef lint
static char sccsid[] = "@(#)com7.c 1.2 11/28/84";
#endif
#include "externs.h"
fight(enemy,strength)
int enemy,strength;
{
int lifeline = 0;
int hurt;
char auxbuf[LINELENGTH];
char *next;
int i;
int exhaustion;
fighton:
time++;
snooze -= 5;
if (snooze > time)
exhaustion = CYCLE/(snooze - time);
else {
puts("You collapse exhausted, and he pulverizes your skull.");
die();
}
if (snooze - time < 20)
puts("You look tired! I hope you're able to fight.");
next = getcom(auxbuf, LINELENGTH, "<fight!>-: ", 0);
for (i=0; next && i < 10; i++)
next = getword(next, words[i], -1);
parse();
switch(wordvalue[wordnumber]){
case KILL:
case SMITE:
if (testbit(inven,TWO_HANDED))
hurt = rnd(70) - 2 * card(injuries,NUMOFINJURIES) - ucard(wear) - exhaustion;
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))
hurt = rnd(15) - card(injuries,NUMOFINJURIES) - exhaustion;
else
hurt = rnd(7) - encumber;
if (hurt < 5)
switch(rnd(3)){
case 0:
puts("You swung wide and missed.");
break;
case 1:
puts("He checked your blow. CLASH! CLANG!");
break;
case 2:
puts("His filthy tunic hangs by one less thread.");
break;
}
else if (hurt < 10){
switch(rnd(3)){
case 0:
puts("He's bleeding.");
break;
case 1:
puts("A trickle of blood runs down his face.");
break;
case 2:
puts("A huge purple bruise is forming on the side of his face.");
break;
}
lifeline++;
}
else if (hurt < 20){
switch(rnd(3)){
case 0:
puts("He staggers back quavering.");
break;
case 1:
puts("He jumps back with his hand over the wound.");
break;
case 2:
puts("His shirt falls open with a swath across the chest.");
break;
}
lifeline += 5;
}
else if (hurt < 30){
switch(rnd(3)){
case 0:
printf("A bloody gash opens up on his %s side.\n",(rnd(2) ? "left" : "right"));
break;
case 1:
puts("The steel bites home and scrapes along his ribs.");
break;
case 2:
puts("You pierce him, and his breath hisses through clenched teeth.");
break;
}
lifeline += 10;
}
else if (hurt < 40){
switch(rnd(3)){
case 0:
puts("You smite him to the ground.");
if (strength - lifeline > 20)
puts("But in a flurry of steel he regains his feet!");
break;
case 1:
puts("The force of your blow sends him to his knees.");
puts("His arm swings lifeless at his side.");
break;
case 2:
puts("Clutching his blood drenched shirt, he collapses stunned.");
break;
}
lifeline += 20;
}
else {
switch(rnd(3)){
case 0:
puts("His ribs crack under your powerful swing, flooding his lungs with blood.");
break;
case 1:
puts("You shatter his upheld arm in a spray of blood. The blade continues deep");
puts("into his back, severing the spinal cord.");
lifeline += 25;
break;
case 2:
puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground.");
lifeline += 25;
break;
}
lifeline += 30;
}
break;
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)){
printf("Lifting the amulet from you, ");
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();
}
if (testbit(inven,AMULET)){
clearbit(inven,AMULET);
carrying -= objwt[AMULET];
encumber -= objcumber[AMULET];
}
else
clearbit(wear,AMULET);
puts("he flees down the dark caverns.");
clearbit(location[position].objects,DARK);
injuries[SKULL] = 1;
followfight = time;
return (0);
}
else{
puts("I'm afraid you have been killed.");
die();
}
}
else{
puts("You escape stunned and disoriented from the fight.");
puts("A victorious bellow echoes from the battlescene.");
if (back && position != back)
move(back,BACK);
else if (ahead &&position != ahead)
move(ahead,AHEAD);
else if (left && position != left)
move(left,LEFT);
else if (right && position != right)
move(right,RIGHT);
else
move(location[position].down,AHEAD);
return(0);
}
case SHOOT:
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);
carrying -= objwt[LASER];
encumber -= objcumber[LASER];
}
}
else
puts("Unfortunately, you don't have a blaster handy.");
break;
case DROP:
case DRAW:
cypher();
time--;
break;
default:
puts("You don't have a chance, he is too quick.");
break;
}
if (lifeline >= strength){
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);
power += 2;
notes[JINXED]++;
return(0);
}
puts("He attacks...");
/* some embellisments */
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]){
injuries[hurt] = 1;
printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
}
else
puts("You emerge unscathed.");
if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){
puts("I'm afraid you have suffered fatal injuries.");
die();
}
goto fighton;
}
SHAR_EOF
if test 6486 -ne "`wc -c battlestar/com7.c`"
then
echo shar: error transmitting battlestar/com7.c '(should have been 6486 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/misc.c
#ifndef lint
static char sccsid[] = "@(#)misc.c 1.1 11/18/84";
#endif
#include "externs.h"
card(array, size) /* for beenthere, injuries */
register char *array;
int size;
{
register char *end = array + size;
register int i = 0;
while (array < end)
if (*array++)
i++;
return (i);
}
ucard(array)
register unsigned *array;
{
register int j = 0, n;
for (n = 0; n < NUMOFOBJECTS; n++)
if (testbit(array, n))
j++;
return (j);
}
SHAR_EOF
if test 452 -ne "`wc -c battlestar/misc.c`"
then
echo shar: error transmitting battlestar/misc.c '(should have been 452 characters)'
fi
cat << \SHAR_EOF > battlestar/parse.c
#ifndef lint
static char sccsid[] = "@(#)parse.c 1.1 11/18/84";
#endif
#include "externs.h"
wordinit()
{
register struct wlist *w;
for (w = wlist; w->string; w++)
install(w);
}
hash(s)
register char *s;
{
register hashval = 0;
while (*s) {
hashval += *s++;
hashval *= HASHMUL;
hashval &= HASHMASK;
}
return hashval;
}
struct wlist *
lookup(s)
char *s;
{
register struct wlist *wp;
for (wp = hashtab[hash(s)]; wp != NULL; wp = wp->next)
if (*s == *wp->string && strcmp(s, wp->string) == 0)
return wp;
return NULL;
}
install(wp)
register struct wlist *wp;
{
int hashval;
if (lookup(wp->string) == NULL) {
hashval = hash(wp->string);
wp->next = hashtab[hashval];
hashtab[hashval] = wp;
} else
printf("Multiply defined %s.\n", wp->string);
}
parse()
{
register struct wlist *wp;
register n;
wordnumber = 0; /* for cypher */
for (n = 0; n <= wordcount; n++) {
if ((wp = lookup(words[n])) == NULL) {
wordvalue[n] = -1;
wordtype[n] = -1;
} else {
wordvalue[n] = wp -> value;
wordtype[n] = wp -> article;
}
}
}
SHAR_EOF
if test 1083 -ne "`wc -c battlestar/parse.c`"
then
echo shar: error transmitting battlestar/parse.c '(should have been 1083 characters)'
fi
cat << \SHAR_EOF > battlestar/room.c
#ifndef lint
static char sccsid[] = "@(#)room.c 1.2 11/28/84";
#endif
#include "externs.h"
writedes()
{
int compass;
register char *p;
register c;
printf("\n\t%s\n", location[position].name);
if (beenthere[position] < 3) {
compass = NORTH;
for (p = location[position].desc; c = *p++;)
if (c != '-' && c != '*' && c != '+')
putchar(c);
else {
if (c != '*')
printf(truedirec(compass, c));
compass++;
}
}
}
printobjs()
{
register unsigned int *p = location[position].objects;
register n;
printf("\n");
for (n = 0; n < NUMOFOBJECTS; n++)
if (testbit(p, n) && objdes[n])
puts(objdes[n]);
}
whichway(here)
struct room here;
{
switch(direction) {
case NORTH:
left = here.west;
right = here.east;
ahead = here.north;
back = here.south;
break;
case SOUTH:
left = here.east;
right = here.west;
ahead = here.south;
back = here.north;
break;
case EAST:
left = here.north;
right = here.south;
ahead = here.east;
back = here.west;
break;
case WEST:
left = here.south;
right = here.north;
ahead = here.west;
back = here.east;
break;
}
}
char *
truedirec(way, option)
int way;
char option;
{
switch(way) {
case NORTH:
switch(direction) {
case NORTH:
return("ahead");
case SOUTH:
return(option == '+' ? "behind you" : "back");
case EAST:
return("left");
case WEST:
return("right");
}
case SOUTH:
switch(direction) {
case NORTH:
return(option == '+' ? "behind you" : "back");
case SOUTH:
return("ahead");
case EAST:
return("right");
case WEST:
return("left");
}
case EAST:
switch(direction) {
case NORTH:
return("right");
case SOUTH:
return("left");
case EAST:
return("ahead");
case WEST:
return(option == '+' ? "behind you" : "back");
}
case WEST:
switch(direction) {
case NORTH:
return("left");
case SOUTH:
return("right");
case EAST:
return(option == '+' ? "behind you" : "back");
case WEST:
return("ahead");
}
default:
printf("Error: room %d. More than four directions wanted.", position);
return("!!");
}
}
newway(thisway)
int thisway;
{
switch(direction){
case NORTH:
switch(thisway){
case LEFT:
direction = WEST;
break;
case RIGHT:
direction = EAST;
break;
case BACK:
direction = SOUTH;
break;
}
break;
case SOUTH:
switch(thisway){
case LEFT:
direction = EAST;
break;
case RIGHT:
direction = WEST;
break;
case BACK:
direction = NORTH;
break;
}
break;
case EAST:
switch(thisway){
case LEFT:
direction = NORTH;
break;
case RIGHT:
direction = SOUTH;
break;
case BACK:
direction = WEST;
break;
}
break;
case WEST:
switch(thisway){
case LEFT:
direction = SOUTH;
break;
case RIGHT:
direction = NORTH;
break;
case BACK:
direction = EAST;
break;
}
break;
}
}
SHAR_EOF
if test 3088 -ne "`wc -c battlestar/room.c`"
then
echo shar: error transmitting battlestar/room.c '(should have been 3088 characters)'
fi
cat << \SHAR_EOF > battlestar/save.c
#ifndef lint
static char sccsid[] = "@(#)save.c 1.2 11/28/84";
#endif
#include "externs.h"
restore()
{
char *getenv();
char *home;
char home1[100];
register int n;
int tmp;
register FILE *fp;
home = getenv("HOME");
strcpy(home1, home);
strcat(home1, "/Bstar");
if ((fp = fopen(home1, "r")) == 0) {
perror(home1);
return;
}
fread(&WEIGHT, sizeof WEIGHT, 1, fp);
fread(&CUMBER, sizeof CUMBER, 1, fp);
fread(&clock, sizeof clock, 1, fp);
for (n = 1; n <= NUMOFROOMS; n++) {
fread(location[n].link, sizeof location[n].link, 1, fp);
fread(location[n].objects, sizeof location[n].objects, 1, fp);
}
fread(inven, sizeof inven, 1, fp);
fread(wear, sizeof wear, 1, fp);
fread(injuries, sizeof injuries, 1, fp);
fread(notes, sizeof notes, 1, fp);
fread(&direction, sizeof direction, 1, fp);
fread(&position, sizeof position, 1, fp);
fread(&time, sizeof time, 1, fp);
fread(&tmp, sizeof tmp, 1, fp);
location = tmp ? dayfile : nightfile;
fread(&fuel, sizeof fuel, 1, fp);
fread(&torps, sizeof torps, 1, fp);
fread(&carrying, sizeof carrying, 1, fp);
fread(&encumber, sizeof encumber, 1, fp);
fread(&rythmn, sizeof rythmn, 1, fp);
fread(&followfight, sizeof followfight, 1, fp);
fread(&ate, sizeof ate, 1, fp);
fread(&snooze, sizeof snooze, 1, fp);
fread(&meetgirl, sizeof meetgirl, 1, fp);
fread(&followgod, sizeof followgod, 1, fp);
fread(&godready, sizeof godready, 1, fp);
fread(&win, sizeof win, 1, fp);
fread(&wintime, sizeof wintime, 1, fp);
fread(&matchlight, sizeof matchlight, 1, fp);
fread(&matchcount, sizeof matchcount, 1, fp);
fread(&loved, sizeof loved, 1, fp);
fread(&pleasure, sizeof pleasure, 1, fp);
fread(&power, sizeof power, 1, fp);
fread(&ego, sizeof ego, 1, fp);
}
save()
{
char *getenv();
char *home;
char home1[100];
register int n;
int tmp;
FILE *fp;
home = getenv("HOME");
strcpy(home1, home);
strcat(home1, "/Bstar");
if ((fp = fopen(home1, "w")) == 0) {
perror(home1);
return;
}
printf("Saved in %s.\n", home1);
fwrite(&WEIGHT, sizeof WEIGHT, 1, fp);
fwrite(&CUMBER, sizeof CUMBER, 1, fp);
fwrite(&clock, sizeof clock, 1, fp);
for (n = 1; n <= NUMOFROOMS; n++) {
fwrite(location[n].link, sizeof location[n].link, 1, fp);
fwrite(location[n].objects, sizeof location[n].objects, 1, fp);
}
fwrite(inven, sizeof inven, 1, fp);
fwrite(wear, sizeof wear, 1, fp);
fwrite(injuries, sizeof injuries, 1, fp);
fwrite(notes, sizeof notes, 1, fp);
fwrite(&direction, sizeof direction, 1, fp);
fwrite(&position, sizeof position, 1, fp);
fwrite(&time, sizeof time, 1, fp);
tmp = location == dayfile;
fwrite(&tmp, sizeof tmp, 1, fp);
fwrite(&fuel, sizeof fuel, 1, fp);
fwrite(&torps, sizeof torps, 1, fp);
fwrite(&carrying, sizeof carrying, 1, fp);
fwrite(&encumber, sizeof encumber, 1, fp);
fwrite(&rythmn, sizeof rythmn, 1, fp);
fwrite(&followfight, sizeof followfight, 1, fp);
fwrite(&ate, sizeof ate, 1, fp);
fwrite(&snooze, sizeof snooze, 1, fp);
fwrite(&meetgirl, sizeof meetgirl, 1, fp);
fwrite(&followgod, sizeof followgod, 1, fp);
fwrite(&godready, sizeof godready, 1, fp);
fwrite(&win, sizeof win, 1, fp);
fwrite(&wintime, sizeof wintime, 1, fp);
fwrite(&matchlight, sizeof matchlight, 1, fp);
fwrite(&matchcount, sizeof matchcount, 1, fp);
fwrite(&loved, sizeof loved, 1, fp);
fwrite(&pleasure, sizeof pleasure, 1, fp);
fwrite(&power, sizeof power, 1, fp);
fwrite(&ego, sizeof ego, 1, fp);
}
SHAR_EOF
if test 3415 -ne "`wc -c battlestar/save.c`"
then
echo shar: error transmitting battlestar/save.c '(should have been 3415 characters)'
fi
# End of shell archive
exit 0
More information about the Comp.sources.unix
mailing list