xref: /csrg-svn/games/battlestar/com6.c (revision 69064)
118720Sedward /*
260750Sbostic  * Copyright (c) 1983, 1993
360750Sbostic  *	The Regents of the University of California.  All rights reserved.
434234Sbostic  *
542567Sbostic  * %sccs.include.redist.c%
618720Sedward  */
718720Sedward 
817380Sedward #ifndef lint
9*69064Sbostic static char sccsid[] = "@(#)com6.c	8.2 (Berkeley) 04/28/95";
1034234Sbostic #endif /* not lint */
1117380Sedward 
12*69064Sbostic #include "extern.h"
1341167Sbostic #include "pathnames.h"
1417380Sedward 
launch()1517380Sedward launch()
1617380Sedward {
1717380Sedward 	if (testbit(location[position].objects,VIPER) && !notes[CANTLAUNCH]){
1817380Sedward 		if (fuel > 4){
1917380Sedward 			clearbit(location[position].objects,VIPER);
2017380Sedward 			position = location[position].up;
2117380Sedward 			notes[LAUNCHED] = 1;
2217380Sedward 			time++;
2317380Sedward 			fuel -= 4;
2417380Sedward 			puts("You climb into the viper and prepare for launch.");
2517380Sedward 			puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat.");
2617380Sedward 			return(1);
2717380Sedward 		}
2817380Sedward 		else
2917380Sedward 			puts("Not enough fuel to launch.");
3017380Sedward 	 }
3117380Sedward 	 else
3217380Sedward 		puts("Can't launch.");
3317380Sedward 	 return(0);
3417380Sedward }
3517380Sedward 
land()3617380Sedward land()
3717380Sedward {
3817380Sedward 	if (notes[LAUNCHED] && testbit(location[position].objects,LAND) && location[position].down){
3917380Sedward 		notes[LAUNCHED] = 0;
4017380Sedward 		position = location[position].down;
4117380Sedward 		setbit(location[position].objects,VIPER);
4217380Sedward 		fuel -= 2;
4317380Sedward 		time++;
4417380Sedward 		puts("You are down.");
4517380Sedward 		return(1);
4617380Sedward 	}
4717380Sedward 	else
4817380Sedward 		puts("You can't land here.");
4917380Sedward 	return(0);
5017380Sedward }
5117380Sedward 
die()5217380Sedward die() 		/* endgame */
5317380Sedward {
5417380Sedward 	printf("bye.\nYour rating was %s.\n", rate());
5517380Sedward 	post(' ');
5617380Sedward 	exit(0);
5717380Sedward }
5817380Sedward 
live()5917380Sedward live()
6017380Sedward {
6117380Sedward 	puts("\nYou win!");
6217380Sedward 	post('!');
6317380Sedward 	exit(0);
6417380Sedward }
6517380Sedward 
6641445Sbostic /*
6741445Sbostic  * sigh -- this program thinks "time" is an int.  It's easier to not load
6841445Sbostic  * <time.h> than try and fix it.
6941445Sbostic  */
7041445Sbostic #define KERNEL
7117380Sedward #include <sys/time.h>
7241445Sbostic #undef KERNEL
7341445Sbostic 
post(ch)7417380Sedward post(ch)
7517380Sedward char ch;
7617380Sedward {
7717380Sedward 	FILE *fp;
7817380Sedward 	struct timeval tv;
7941445Sbostic 	char *date, *ctime();
8017439Sedward 	int s = sigblock(sigmask(SIGINT));
8117380Sedward 
8217380Sedward 	gettimeofday(&tv, (struct timezone *)0);	/* can't call time */
8317380Sedward 	date = ctime(&tv.tv_sec);
8417380Sedward 	date[24] = '\0';
8541167Sbostic 	if (fp = fopen(_PATH_SCORE,"a")) {
8617380Sedward 		fprintf(fp, "%s  %8s  %c%20s", date, uname, ch, rate());
8717380Sedward 		if (wiz)
8817380Sedward 			fprintf(fp, "   wizard\n");
8917380Sedward 		else if (tempwiz)
9017380Sedward 			fprintf(fp, "   WIZARD!\n");
9117380Sedward 		else
9217380Sedward 			fprintf(fp, "\n");
9317380Sedward 	} else
9441167Sbostic 		perror(_PATH_SCORE);
9517439Sedward 	sigsetmask(s);
9617380Sedward }
9717380Sedward 
9817380Sedward char *
rate()9917380Sedward rate()
10017380Sedward {
10117380Sedward 	int score;
10217380Sedward 
10317380Sedward 	score = max(max(pleasure,power),ego);
10417380Sedward 	if (score == pleasure){
10517380Sedward 		if (score < 5)
10617380Sedward 			return("novice");
10717380Sedward 		else if (score < 20)
10817380Sedward 			return("junior voyeur");
10917380Sedward 		else if (score < 35)
11017380Sedward 			return("Don Juan");
11117380Sedward 		else return("Marquis De Sade");
11217380Sedward 	}
11317380Sedward 	else if (score == power){
11417380Sedward 		if (score < 5)
11517380Sedward 			return("serf");
11617380Sedward 		else if (score < 8)
11717380Sedward 			return("Samurai");
11817380Sedward 		else if (score < 13)
11917380Sedward 			return("Klingon");
12017380Sedward 		else if (score < 22)
12117380Sedward 			return("Darth Vader");
12217380Sedward 		else return("Sauron the Great");
12317380Sedward 	}
12417380Sedward 	else{
12517380Sedward 		if (score < 5)
12617380Sedward 			return("Polyanna");
12717380Sedward 		else if (score < 10)
12817380Sedward 			return("philanthropist");
12917380Sedward 		else if (score < 20)
13017380Sedward 			return("Tattoo");
13117380Sedward 		else return("Mr. Roarke");
13217380Sedward 	}
13317380Sedward }
13417380Sedward 
drive()13517380Sedward drive()
13617380Sedward {
13717380Sedward 	if (testbit(location[position].objects,CAR)){
13817439Sedward 		puts("You hop in the car and turn the key.  There is a perceptible grating noise,");
13917380Sedward 		puts("and an explosion knocks you unconscious...");
14017380Sedward 		clearbit(location[position].objects,CAR);
14117380Sedward 		setbit(location[position].objects,CRASH);
14217380Sedward 		injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1;
14317380Sedward 		time += 15;
14417380Sedward 		zzz();
14517380Sedward 		return(0);
14617380Sedward 	}
14717380Sedward 	else
14817380Sedward 		puts("There is nothing to drive here.");
14917380Sedward 	return(-1);
15017380Sedward }
15117380Sedward 
ride()15217380Sedward ride()
15317380Sedward {
15417380Sedward 	if (testbit(location[position].objects,HORSE)){
15517380Sedward 		puts("You climb onto the stallion and kick it in the guts.  The stupid steed launches");
15617380Sedward 		puts("forward through bush and fern.  You are thrown and the horse gallups off.");
15717380Sedward 		clearbit(location[position].objects,HORSE);
15817380Sedward 		while (!(position = rnd(NUMOFROOMS+1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere);
15917380Sedward 		setbit(location[position].objects,HORSE);
16017380Sedward 		if (location[position].north)
16117380Sedward 			position = location[position].north;
16217380Sedward 		else if (location[position].south)
16317380Sedward 			position = location[position].south;
16417380Sedward 		else if (location[position].east)
16517380Sedward 			position = location[position].east;
16617380Sedward 		else
16717380Sedward 			position = location[position].west;
16817380Sedward 		return(0);
16917380Sedward 	}
17017380Sedward 	else puts("There is no horse here.");
17117380Sedward 	return(-1);
17217380Sedward }
17317380Sedward 
light()17417380Sedward light()		/* synonyms = {strike, smoke} */
17517380Sedward {		/* for matches, cigars */
17617380Sedward 	if (testbit(inven,MATCHES) && matchcount){
17717380Sedward 		puts("Your match splutters to life.");
17817380Sedward 		time++;
17917380Sedward 		matchlight = 1;
18017380Sedward 		matchcount--;
18117380Sedward 		if (position == 217){
18217380Sedward 			puts("The whole bungalow explodes with an intense blast.");
18317380Sedward 			die();
18417380Sedward 		}
18517380Sedward 	}
18617380Sedward 	else puts("You're out of matches.");
18717380Sedward }
188